3 Aralık 2007 Pazartesi

Creating Dropdown Button

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
InitializeMyToolBar();
}

public void InitializeMyToolBar()
{

ToolBarButton toolBarButton3 = new ToolBarButton();

ToolBar toolBar1 = new ToolBar();
toolBar1.ButtonSize = new System.Drawing.Size(75, 23);
toolBar1.TextAlign = System.Windows.Forms.ToolBarTextAlign.Right;
MenuItem menuItem1 = new MenuItem("Print");
MenuItem menuItem2 = new MenuItem("Close");
menuItem1.Click += new System.EventHandler(this.Print_Click);
menuItem2.Click += new System.EventHandler(this.Close_Click);
MenuItem[] mi = new MenuItem[2] {menuItem1, menuItem2};
ContextMenu contextMenu1 = new ContextMenu(mi);

toolBar1.Buttons.Add(toolBarButton3);

toolBar1.ShowToolTips = true;

toolBarButton3.Text = "Operations";

toolBarButton3.Style = ToolBarButtonStyle.DropDownButton;

toolBarButton3.ToolTipText = "Operations";
toolBarButton3.ImageIndex = 0;
toolBarButton3.DropDownMenu = contextMenu1;

panel1.Controls.Add(toolBar1);
}

private void Print_Click(object sender, EventArgs e)
{
MessageBox.Show("Print");
}

private void Close_Click(object sender, EventArgs e)
{
MessageBox.Show("Close");
}

}

0 yorum: