.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

RibbonButton side by side

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
FRPT1257
1906 Views, 4 Replies

RibbonButton side by side

I have the following code to create an RibbonButton.

 

This way buttons appeats side by side.

How can I put them in columns of 3 in each columns, followed verically and not just side by side horizontaly?

Autodesk.Windows.RibbonButton button = new RibbonButton();
button.Text = displayName;
button.Size = ribbonItemSize;
button.Orientation = System.Windows.Controls.Orientation.Horizontal;
button.Image = getBitmap(standardBitmap, 16, 16);
button.LargeImage = getBitmap(largeBitmap, 32, 32);
button.ShowText = showText;
button.CommandParameter = commandParameter;

 

Thanks & Regards,

Rui

4 REPLIES 4
Message 2 of 5
moogalm
in reply to: FRPT1257

Hey There,

 

How can I put them in columns of 3 in each columns, followed verically and not just side by side horizontaly?

 

Sorry I have not understood completely above statement ,nonetheless I have arranged button in 4X4 pattern on panel in other words two rows and two columns of buttons.

 

Do let me know if this doesn't help you.

 

[CommandMethod("SimpleButton")]
public void SimpleButton()
{
Autodesk.Windows.RibbonControl ribbonControl = Autodesk.Windows.ComponentManager.Ribbon;

RibbonTab Tab = new RibbonTab();
Tab.Title = "Test Ribbon";
Tab.Id = "TESTRIBBON_TAB_ID";

ribbonControl.Tabs.Add(Tab);

Autodesk.Windows.RibbonPanelSource srcPanel = new RibbonPanelSource();
srcPanel.Title = "Panel1";
srcPanel.Id = "PANEL_1_ID";

RibbonPanel Panel = new RibbonPanel();
Panel.Source = srcPanel;
Tab.Panels.Add(Panel);
/*Create Button 1*/
Autodesk.Windows.RibbonButton button1 = new RibbonButton();
button1.Text = "Button1";
button1.Size = RibbonItemSize.Large;
/*
Embedding Image resource to your project
1.On the Project menu, choose Add Existing Item.
2.Navigate to the image you want to add to your project. Click the Open button to add the image to your project's file list.
3.Right-click the image in your project's file list and choose Properties. The Properties window appears.
4.Find the Build Action property in the Properties window. Change its value to Embedded Resource.
*
Then opens a stream on the embedded image. The name used to refer to the image takes this form:
<namespace>.<image name>.<format>  */
button1.Image = LoadImage("TestSharp2015.Koala.jpg", 16, 16);
button1.LargeImage = LoadImage("TestSharp2015.Koala.jpg", 32, 32);
button1.ShowText = true;
                    
/*Create Button 2*/
            
Autodesk.Windows.RibbonButton button2 = new RibbonButton();
button2.Text = "Button2";
button2.ShowText = true;
button2.Image = LoadImage("TestSharp2015.Koala.jpg", 16, 16);
button2.LargeImage = LoadImage("TestSharp2015.Koala.jpg", 32, 32);
button2.Size = RibbonItemSize.Large;
Tab.IsActive = true;

/*Create Button 3*/
Autodesk.Windows.RibbonButton button3 = new RibbonButton();
button3.Text = "Button3";
button3.ShowText = true;
button3.Image = LoadImage("TestSharp2015.Koala.jpg", 16, 16);
button3.LargeImage = LoadImage("TestSharp2015.Koala.jpg", 32, 32);
button3.Size = RibbonItemSize.Large;
Tab.IsActive = true;

/*Create Button 4*/
Autodesk.Windows.RibbonButton button4 = new RibbonButton();
button4.Text = "Button4";
button4.ShowText = true;
button4.Image = LoadImage("TestSharp2015.Koala.jpg", 16, 16);
button4.LargeImage = LoadImage("TestSharp2015.Koala.jpg", 32, 32);
button4.Size = RibbonItemSize.Large;
Tab.IsActive = true;

Autodesk.Windows.RibbonRowPanel ribRowPanel1 = new RibbonRowPanel();
ribRowPanel1.Items.Add(button1);
ribRowPanel1.Items.Add(new RibbonRowBreak());
ribRowPanel1.Items.Add(button2);
srcPanel.Items.Add(ribRowPanel1);
RibbonSeparator rsP = new RibbonSeparator();
rsP.SeparatorStyle = RibbonSeparatorStyle.Invisible;
srcPanel.Items.Add(rsP);
Autodesk.Windows.RibbonRowPanel ribRowPanel2 = new RibbonRowPanel();
ribRowPanel2.Items.Add(button3);
ribRowPanel2.Items.Add(new RibbonRowBreak());
ribRowPanel2.Items.Add(button4);
srcPanel.Items.Add(ribRowPanel2);
                      
}

public BitmapImage LoadImage(string imageName, int Height, int Width)
{
BitmapImage image = new BitmapImage();

image.BeginInit();
image.StreamSource = Assembly.GetExecutingAssembly().GetManifestResourceStream(imageName);
// image.UriSource = new Uri(imageName);
image.DecodePixelHeight = Height;
image.DecodePixelWidth = Width;
image.EndInit();
return image;
}

 

Message 3 of 5
FRPT1257
in reply to: moogalm

Great!! 🙂

I was missing the "new RibbonRowBreak()"

Thanks
Message 4 of 5
srikanthc85
in reply to: moogalm

HI,

 

Can you send the code for .Net.

 

I am finding it difficult to add image to the button, please see the below. I am missing any reference ?

 

button1.Image = LoadImage("TestSharp2015.Koala.jpg", 16, 16)  - This command is not working with me

 

 

Code:

 

Try

' Creating Ribbon Control
Dim AcadRibbonControl As RibbonControl = New RibbonControl

' Creating Tab
Dim AcadRibbonTab As RibbonTab = New RibbonTab
AcadRibbonTab.Title = "Crane Tab"
AcadRibbonTab.Id = "CraneTab"
AcadRibbonTab.IsContextualTab = False

' Add Tab to Ribbon Control
AcadRibbonControl.Tabs.Add(AcadRibbonTab)

' Creating Ribbon Panel Source in to which place Ribbon Items
Dim AcadRibbonPanelSource As RibbonPanelSource = New RibbonPanelSource
AcadRibbonPanelSource.Title = "Crane Planner"
AcadRibbonPanelSource.Id = "CranePlanner"
'AcadRibbonPanelSource.Items.Add(AcadRibbonRow)

' Creating Ribbon Panel
Dim AcadRibbonPanel As RibbonPanel = New RibbonPanel
AcadRibbonPanel.Source = AcadRibbonPanelSource

' Add Ribbon Panel to the Ribbon Tab
AcadRibbonTab.Panels.Add(AcadRibbonPanel)

' Creating a Button
Dim AcadButton As RibbonButton = New RibbonButton
AcadButton.Text = "Crane Form"
AcadButton.Orientation = Windows.Controls.Orientation.Vertical
AcadButton.Size = RibbonItemSize.Large
AcadButton.ShowImage = True
AcadButton.ShowText = True

'Embedding Image resource to your project
'1.On the Project menu, choose Add Existing Item.
'2.Navigate to the image you want to add to your project. Click the Open button to add the image to your project's file list.
'3.Right-click the image in your project's file list and choose Properties. The Properties window appears.
'4.Find the Build Action property in the Properties window. Change its value to Embedded Resource.

' Assiging Image to Button


AcadRibbonTab.IsActive = True

' Create a Row to add Ribbon Button
Dim AcadRibbonRow As RibbonRowPanel = New RibbonRowPanel
AcadRibbonRow.Items.Add(AcadButton)
'AcadRibbonTab.Panels.Add(AcadRibbonPanel)
AcadRibbonPanelSource.Items.Add(AcadRibbonRow)

 

Catch ex As System.Exception

MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
End Try

Message 5 of 5
FRPT1257
in reply to: srikanthc85

Take a look in the following code:

 

public static RibbonButton CreateButton(string displayName, RibbonItemSize ribbonItemSize, Bitmap standardBitmap, Bitmap largeBitmap,

 

bool showText, string commandParameter)

{

Autodesk.Windows.

RibbonButton button = new RibbonButton();

button.Text = displayName;

button.Size = ribbonItemSize;

button.Orientation = System.Windows.Controls.

Orientation.Horizontal;

 

if (standardBitmap != null)

button.Image = getBitmap(standardBitmap, 16, 16);

 

if (largeBitmap != null)

button.LargeImage = getBitmap(largeBitmap, 32, 32);

button.ShowText = showText;

button.CommandParameter = commandParameter;

 

return button;

}

 

static BitmapImage getBitmap(Bitmap bitmap, int height, int width)

{

 

MemoryStream stream = new MemoryStream();

bitmap.Save(stream, System.Drawing.Imaging.

ImageFormat.Png);

 

BitmapImage bmp = new BitmapImage();

bmp.BeginInit();

bmp.StreamSource =

new MemoryStream(stream.ToArray());

bmp.DecodePixelHeight = height;

bmp.DecodePixelWidth = width;

bmp.EndInit();

 

return bmp;

}

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost