按钮摆放问题,很简单,希望大侠指导
想做成想AutoCAD2010里这样的按钮,但我做成都是这样的,没有分成多行,怎么改都没有实现,哪位大侠做过,给指点一下,谢谢分成多行和设计的图例没有关系,这种效果要复制一个像截图中面板对话框启动器再做修改。 大侠,我自己做的按钮,是用代码写的,不是用cui文件做的,你说的,我不怎么明白,能说的具体点吗
RibbonPanelSource sourcePanel2 = new RibbonPanelSource();
sourcePanel2.Title = "所有图例";//Ribbon面板的标题
RibbonPanel ribPanel2 = new RibbonPanel();//创建Ribbon面板
ribPanel2.CanToggleOrientation = true;
//ribPanel2.Tab.
//ribPanel2.ResizeStyle = RibbonResizeStyles.NeverResizeItemWidth;
ribPanel2.Source = sourcePanel2;//设置Ribbon面板的内容
tab.Panels.Add(ribPanel2);//将Ribbon面板添加到选项卡中
RibbonToggleButton ribTogBtn1 = new RibbonToggleButton();
ribTogBtn1.ShowImage = true;
ribTogBtn1.Image = ConvertDrawingImage2MediaImageSource(Res.plus);
ribTogBtn1.LargeImage = ConvertDrawingImage2MediaImageSource(Res.plus);
ribTogBtn1.Size = RibbonItemSize.Standard;
ribTogBtn1.Orientation = System.Windows.Controls.Orientation.Horizontal;
ribTogBtn1.IsSelectedForEditing = false;
sourcePanel2.Items.Add(ribTogBtn1);
RibbonToggleButton ribTogBtn2 = new RibbonToggleButton();
ribTogBtn2.ShowImage = true;
ribTogBtn2.Image = ConvertDrawingImage2MediaImageSource(Res.plus);
ribTogBtn2.LargeImage = ConvertDrawingImage2MediaImageSource(Res.plus);
ribTogBtn2.Size = RibbonItemSize.Standard;
ribTogBtn1.Orientation = System.Windows.Controls.Orientation.Horizontal;
sourcePanel2.Items.Add(ribTogBtn2);
RibbonToggleButton ribTogBtn3 = new RibbonToggleButton();
ribTogBtn3.ShowImage = true;
ribTogBtn3.Image = ConvertDrawingImage2MediaImageSource(Res.plus);
ribTogBtn3.LargeImage = ConvertDrawingImage2MediaImageSource(Res.plus);
ribTogBtn3.Size = RibbonItemSize.Standard;
ribTogBtn3.Orientation = System.Windows.Controls.Orientation.Horizontal;
sourcePanel2.Items.Add(ribTogBtn3);
我是这么写的 有人会吗,指导小妹一下下呗 添加换行
row.Items.Add(New RibbonRowBreak) 哥哥,能说的具体点吗,小妹是个新手啊 河伯 发表于 2015-6-5 11:13 static/image/common/back.gif
添加换行
row.Items.Add(New RibbonRowBreak)
问题解决了,谢谢,小妹很感谢。 dpec1982 发表于 2015-6-5 15:40
问题解决了,谢谢,小妹很感谢。
小妹你的代码怎么用 本帖最后由 Leo1980 于 2019-9-5 11:38 编辑
这个资料参考一下
/*
* RibbonControl
* -- RibbonTab
* --
*
*
*
*
*
*
*
*
*
*
*
* */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Windows.Media.Imaging;
using System.Reflection;
using System.Windows.Input;
using System.Xml;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.GraphicsInterface;
/////////////UI///////////////
using Autodesk.Windows;
using Autodesk.AutoCAD.Ribbon;
namespace Acad2012
{
public class RibbonTest
{
//Autodesk.AutoCAD.ApplicationServices.Application acadApp = null;
public RibbonCombo pan1ribcombo1 = new RibbonCombo();
public RibbonCombo pan3ribcombo = new RibbonCombo();
public RibbonTest()
{
//acadApp = ;
pan3ribcombo.CurrentChanged += new System.EventHandler<RibbonPropertyChangedEventArgs>(pan3ribcombo_CurrentChanged);
}
private void pan3ribcombo_CurrentChanged(object sender, RibbonPropertyChangedEventArgs e)
{
RibbonButton but = pan3ribcombo.Current as RibbonButton;
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(but.Text);
}
public void RibbonSplitButtontest()
{
RibbonButton commandlinebutton = new RibbonButton();
commandlinebutton.Text = "Newly Added Button with command: MyRibbonTestCombo";
commandlinebutton.ShowText = true;
commandlinebutton.ShowImage = true;
commandlinebutton.Image = Images.getBitmap(Resource.cmd16);
commandlinebutton.LargeImage = Images.getBitmap(Resource.cmd32);
commandlinebutton.CommandHandler = new RibbonCommandHandler();
pan1ribcombo1.Items.Add(commandlinebutton);
pan1ribcombo1.Current = commandlinebutton;
}
public void MyRibbon()
{
Autodesk.Windows.RibbonControl ribbonControl = Autodesk.Windows.ComponentManager.Ribbon;
RibbonTab Tab = new RibbonTab();
Tab.Title = "Autodesk .NET forum Ribbon Sample";
Tab.Id = "RibbonSample_TAB_ID";
ribbonControl.Tabs.Add(Tab);
// create Ribbon panels
Autodesk.Windows.RibbonPanelSource panel1Panel = new RibbonPanelSource();
panel1Panel.Title = "Panel1";
RibbonPanel Panel1 = new RibbonPanel();
Panel1.Source = panel1Panel;
Tab.Panels.Add(Panel1);
RibbonButton pan1button1 = new RibbonButton();
pan1button1.Text = "Button1";
pan1button1.ShowText = true;
pan1button1.ShowImage = true;
pan1button1.Image = Images.getBitmap(Resource.cmd16);
pan1button1.LargeImage = Images.getBitmap(Resource.cmd32);
pan1button1.Orientation = System.Windows.Controls.Orientation.Vertical;
pan1button1.Size = RibbonItemSize.Large;
pan1button1.CommandHandler = new RibbonCommandHandler();
RibbonButton pan1button2 = new RibbonButton();
pan1button2.Text = "Button2";
pan1button2.ShowText = true;
pan1button2.ShowImage = true;
pan1button2.Image = Images.getBitmap(Resource.cmd16);
pan1button2.LargeImage = Images.getBitmap(Resource.cmd32);
pan1button2.CommandHandler = new RibbonCommandHandler();
RibbonButton pan1button3 = new RibbonButton();
pan1button3.Text = "Button3";
pan1button3.ShowText = true;
pan1button3.ShowImage = true;
pan1button3.Image = Images.getBitmap(Resource.cmd16);
pan1button3.LargeImage = Images.getBitmap(Resource.cmd32);
pan1button3.CommandHandler = new RibbonCommandHandler();
// Set te propperties for the RibbonCombo
// Te ribboncombo control does not listen to the command handler
pan1ribcombo1.Text = " ";
pan1ribcombo1.ShowText = true;
pan1ribcombo1.MinWidth = 150;
RibbonRowPanel pan1row1 = new RibbonRowPanel();
pan1row1.Items.Add(pan1button2);
pan1row1.Items.Add(new RibbonRowBreak());
pan1row1.Items.Add(pan1button3);
pan1row1.Items.Add(new RibbonRowBreak());
pan1row1.Items.Add(pan1ribcombo1);
panel1Panel.Items.Add(pan1button1);
panel1Panel.Items.Add(new RibbonSeparator());
panel1Panel.Items.Add(pan1row1);
RibbonPanelSource panel2Panel = new RibbonPanelSource();
panel2Panel.Title = "Panel2";
RibbonPanel panel2 = new RibbonPanel();
panel2.Source = panel2Panel;
Tab.Panels.Add(panel2);
RibbonSplitButton pan2splitButton = new RibbonSplitButton();
pan2splitButton.Text = "SplitButton"; //Required not to crash AutoCAD when using cmd locators
pan2splitButton.CommandHandler = new RibbonCommandHandler();
pan2splitButton.ShowText = true;
pan2splitButton.ShowImage = true;
pan2splitButton.Image = Images.getBitmap(Resource.cmd16);
pan2splitButton.LargeImage = Images.getBitmap(Resource.cmd32);
pan2splitButton.IsSplit = true;
pan2splitButton.Size = RibbonItemSize.Large;
RibbonButton pan2button1 = new RibbonButton();
pan2button1.Text = "Button1";
pan2button1.ShowText = true;
pan2button1.ShowImage = true;
pan2button1.Image = Images.getBitmap(Resource.cmd16);
pan2button1.LargeImage = Images.getBitmap(Resource.cmd32);
pan2button1.Size = RibbonItemSize.Large;
pan2button1.Orientation = System.Windows.Controls.Orientation.Vertical;
pan2button1.CommandHandler = new RibbonCommandHandler();
RibbonButton pan2button2 = new RibbonButton();
pan2button2.Text = "Button2";
pan2button2.ShowText = true;
pan2button2.ShowImage = true;
pan2button2.Image = Images.getBitmap(Resource.cmd16);
pan2button2.LargeImage = Images.getBitmap(Resource.cmd32);
pan2button2.CommandHandler = new RibbonCommandHandler();
RibbonButton pan2button3 = new RibbonButton();
pan2button3.Text = "Button3";
pan2button3.ShowText = true;
pan2button3.ShowImage = true;
pan2button3.Image = Images.getBitmap(Resource.cmd16);
pan2button3.LargeImage = Images.getBitmap(Resource.cmd32);
pan2button3.CommandHandler = new RibbonCommandHandler();
pan2splitButton.Items.Add(pan2button1);
pan2splitButton.Items.Add(pan2button2);
RibbonRowPanel pan2row1 = new RibbonRowPanel();
pan2row1.Items.Add(pan2button2);
pan2row1.Items.Add(new RibbonRowBreak());
pan2row1.Items.Add(pan2button3);
pan2row1.Items.Add(new RibbonRowBreak());
pan2row1.Items.Add(new RibbonCombo());
panel2Panel.Items.Add(pan2splitButton);
panel2Panel.Items.Add(pan2row1);
RibbonPanelSource panel3Panel = new RibbonPanelSource();
panel3Panel.Title = "Panel3";
RibbonPanel panel3 = new RibbonPanel();
panel3.Source = panel3Panel;
Tab.Panels.Add(panel3);
RibbonButton pan3button1 = new RibbonButton();
pan3button1.Text = "Button1";
pan3button1.ShowText = true;
pan3button1.ShowImage = true;
pan3button1.Image = Images.getBitmap(Resource.cmd16);
pan3button1.LargeImage = Images.getBitmap(Resource.cmd32);
pan3button1.Size = RibbonItemSize.Large;
pan3button1.Orientation = System.Windows.Controls.Orientation.Vertical;
pan3button1.CommandHandler = new RibbonCommandHandler();
RibbonButton pan3button2 = new RibbonButton();
pan3button2.Text = "Button2";
pan3button2.ShowText = true;
pan3button2.ShowImage = true;
pan3button2.Image = Images.getBitmap(Resource.cmd16);
pan3button2.LargeImage = Images.getBitmap(Resource.cmd32);
pan3button2.Size = RibbonItemSize.Large;
pan3button2.Orientation = System.Windows.Controls.Orientation.Vertical;
pan3button2.CommandHandler = new RibbonCommandHandler();
RibbonButton pan3button3 = new RibbonButton();
pan3button3.Text = "Button3";
pan3button3.ShowText = true;
pan3button3.ShowImage = true;
pan3button3.Image = Images.getBitmap(Resource.cmd16);
pan3button3.LargeImage = Images.getBitmap(Resource.cmd32);
pan3button3.CommandHandler = new RibbonCommandHandler();
RibbonButton pan3button4 = new RibbonButton();
pan3button4.Text = "Button4";
pan3button4.ShowText = true;
pan3button4.ShowImage = true;
pan3button4.Image = Images.getBitmap(Resource.cmd16);
pan3button4.LargeImage = Images.getBitmap(Resource.cmd32);
pan3button4.CommandHandler = new RibbonCommandHandler();
RibbonButton pan3button5 = new RibbonButton();
pan3button5.Text = "Button5";
pan3button5.ShowText = true;
pan3button5.ShowImage = true;
pan3button5.Image = Images.getBitmap(Resource.cmd16);
pan3button5.LargeImage = Images.getBitmap(Resource.cmd32);
pan3button5.CommandHandler = new RibbonCommandHandler();
RibbonRowPanel pan3row1 = new RibbonRowPanel();
pan3row1.Items.Add(pan3button3);
pan3row1.Items.Add(new RibbonRowBreak());
pan3row1.Items.Add(pan3button4);
pan3row1.Items.Add(new RibbonRowBreak());
pan3row1.Items.Add(pan3button5);
panel3Panel.Items.Add(pan3button1);
panel3Panel.Items.Add(pan3row1);
RibbonPanelSource pan4Panel = new RibbonPanelSource();
pan4Panel.Title = "Panel4";
RibbonPanel Panel4 = new RibbonPanel();
Panel4.Source = pan4Panel;
Tab.Panels.Add(Panel4);
RibbonButton pan4button1 = new RibbonButton();
pan4button1.Text = "Button1";
pan4button1.ShowText = true;
pan4button1.ShowImage = true;
pan4button1.Image = Images.getBitmap(Resource.cmd16);
pan4button1.LargeImage = Images.getBitmap(Resource.cmd32);
pan4button1.Size = RibbonItemSize.Large;
pan4button1.Orientation = System.Windows.Controls.Orientation.Vertical;
pan4button1.CommandHandler = new RibbonCommandHandler();
RibbonButton pan4button2 = new RibbonButton();
pan4button2.Text = "Button2";
pan4button2.ShowText = true;
pan4button2.ShowImage = true;
pan4button2.Image = Images.getBitmap(Resource.cmd16);
pan4button2.LargeImage = Images.getBitmap(Resource.cmd32);
pan4button2.CommandHandler = new RibbonCommandHandler();
RibbonButton pan4button3 = new RibbonButton();
pan4button3.Text = "Button3";
pan4button3.ShowText = true;
pan4button3.ShowImage = true;
pan4button3.Image = Images.getBitmap(Resource.cmd16);
pan4button3.LargeImage = Images.getBitmap(Resource.cmd32);
pan4button3.CommandHandler = new RibbonCommandHandler();
RibbonButton pan4button4 = new RibbonButton();
pan4button4.Text = "Button4";
pan4button4.ShowText = true;
pan4button4.ShowImage = true;
pan4button4.Image = Images.getBitmap(Resource.cmd16);
pan4button4.LargeImage = Images.getBitmap(Resource.cmd32);
pan4button4.Size = RibbonItemSize.Large;
pan4button4.Orientation = System.Windows.Controls.Orientation.Vertical;
pan4button4.CommandHandler = new RibbonCommandHandler();
RibbonButton pan4ribcombobutton1 = new RibbonButton();
pan4ribcombobutton1.Text = "Button1";
pan4ribcombobutton1.ShowText = true;
pan4ribcombobutton1.ShowImage = true;
pan4ribcombobutton1.Image = Images.getBitmap(Resource.cmd16);
pan4ribcombobutton1.LargeImage = Images.getBitmap(Resource.cmd32);
pan4ribcombobutton1.CommandHandler = new RibbonCommandHandler();
RibbonButton pan4ribcombobutton2 = new RibbonButton();
pan4ribcombobutton2.Text = "Button2";
pan4ribcombobutton2.ShowText = true;
pan4ribcombobutton2.ShowImage = true;
pan4ribcombobutton2.Image = Images.getBitmap(Resource.cmd16);
pan4ribcombobutton2.LargeImage = Images.getBitmap(Resource.cmd32);
pan4ribcombobutton2.CommandHandler = new RibbonCommandHandler();
pan3ribcombo.Width = 150;
pan3ribcombo.Items.Add(pan4ribcombobutton1);
pan3ribcombo.Items.Add(pan4ribcombobutton2);
pan3ribcombo.Current = pan4ribcombobutton1;
RibbonRowPanel vvorow1 = new RibbonRowPanel();
vvorow1.Items.Add(pan4button2);
vvorow1.Items.Add(new RibbonRowBreak());
vvorow1.Items.Add(pan4button3);
vvorow1.Items.Add(new RibbonRowBreak());
vvorow1.Items.Add(pan3ribcombo);
pan4Panel.Items.Add(pan4button1);
pan4Panel.Items.Add(vvorow1);
pan4Panel.Items.Add(new RibbonSeparator());
pan4Panel.Items.Add(pan4button4);
Tab.IsActive = true;
}
public class RibbonCommandHandler : System.Windows.Input.ICommand
{
public bool CanExecute(object parameter)
{
return true;
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
if (parameter is RibbonButton)
{
RibbonButton button = parameter as RibbonButton;
doc.Editor.WriteMessage("\nRibbonButton Executed: " + button.Text + "\n");
}
}
}
public class Images
{
public static BitmapImage getBitmap(Bitmap image)
{
MemoryStream stream = new MemoryStream();
image.Save(stream, ImageFormat.Png);
BitmapImage bmp = new BitmapImage();
bmp.BeginInit();
bmp.StreamSource = stream;
bmp.EndInit();
return bmp;
}
}
}
}
页:
[1]