Multibuttons - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Multibuttons

floozyfloozy Posts: 38Member
Im creating an application which will have plenty of buttons in the end. So far there are 2 toolbars on the left of the window, the right one displays a different choice of buttons (images from an imageList), depending on which image was clicked on the left toolbar. Here is part of the code

private void vertBtnClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
// Evaluate the Button property to determine which button was clicked.

switch(verticalToolBar.Buttons.IndexOf(e.Button))
{
case 0:
//show a few more buttons
createButtons1();
break;
case 1:
//show some other buttons
createButtons2();
break;
}
}
//some buttons
private void createButtons1()
{
verticalToolBar2.Buttons.Clear();
myFirstBt = new ToolBarButton();
mySecondBt = new ToolBarButton();
verticalToolBar2.ImageList = new ImageList();
verticalToolBar2.ImageList = this.imageListHow;

myFirstBt.ImageIndex = 0;
myFirstBt.ToolTipText = "do something";
mySecondBt.ImageIndex = 1;
//have some methods connected with the buttons
verticalToolBar2.ButtonClick -= new ToolBarButtonClickEventHandler(myBtnClick2);
verticalToolBar2.ButtonClick += new ToolBarButtonClickEventHandler(myBtnClick1);

this.verticalToolBar2.Buttons.AddRange(new ToolBarButton[]{myFirstBt, mySecondBt});

}

//some more buttons
private void createButtons2()
{
verticalToolBar2.Buttons.Clear();
myThirdBt = new ToolBarButton();
myFourthBt = new ToolBarButton();
myFifthBt = new ToolBarButton();
verticalToolBar2.ImageList = new ImageList();
verticalToolBar2.ImageList = this.imageListHow;
myThirdBt.ImageIndex = 2;
myFourthBt.ImageIndex = 3;
myFifthBt.ImageIndex = 4;
myThirdBt.ToolTipText = "do something else";

verticalToolBar2.ButtonClick -= new ToolBarButtonClickEventHandler(myBtnClick1);

verticalToolBar2.ButtonClick += new ToolBarButtonClickEventHandler(myBtnClick2);

verticalToolBar2.Buttons.AddRange(new ToolBarButton[]{myThirdBt, myFourthBt, myFifthBt});

}

After some difficulties it now works as it should.
My new task is to create a kind of multi-button that will show when mouse is hovering over one of the existing buttons (images), then one should be able to choose one of the multi-buttons with mouse click and that chosen button will appear on the toolbar and perform its task, whatever that will be.
Imagine the multi-button like a birds view on a chocolate bar.

Id be glad for any suggestions

Comments

  • floozyfloozy Posts: 38Member
    Hi there, Im trying to create a button that displays a range of buttons, in this case a toolbar full of images. I use the button in an appliction and have a mouseOver methode, everything works exept for the silly chocolate doesnt show up. Any suggestions are welcome!!

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;

    namespace MultiButton
    {

    public class MButton : System.Windows.Forms.Button
    {
    private EventHandler mouseHover; //delegate
    private System.Windows.Forms.Timer myTicker;
    private System.Windows.Forms.ToolBar chocolate;
    private System.Windows.Forms.ToolBarButton toolBarButton1;
    private System.Windows.Forms.ToolBarButton toolBarButton2;

    private System.Windows.Forms.ImageList chocImageList;
    private System.ComponentModel.IContainer components;


    private void InitializeComponent()
    {
    this.components = new System.ComponentModel.Container();
    System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MButton));

    this.chocolate = new System.Windows.Forms.ToolBar();

    this.toolBarButton1 = new System.Windows.Forms.ToolBarButton();

    this.toolBarButton2 = new System.Windows.Forms.ToolBarButton();

    this.chocImageList = new System.Windows.Forms.ImageList(this.components);

    this.chocolate.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
    this.toolBarButton1,
    this.toolBarButton2});

    this.chocolate.Dock = System.Windows.Forms.DockStyle.Right;
    this.chocolate.DropDownArrows = true;
    this.chocolate.ImageList = this.chocImageList;
    this.chocolate.Location = new System.Drawing.Point(113, 17);
    this.chocolate.Name = "chocolate";
    this.chocolate.ShowToolTips = true;
    this.chocolate.Size = new System.Drawing.Size(24, 267);
    this.chocolate.TabIndex = 0;

    this.toolBarButton1.ImageIndex = 0;

    this.toolBarButton2.ImageIndex = 1;

    this.chocImageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;

    this.chocImageList.ImageSize = new System.Drawing.Size(16, 16);
    this.chocImageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("chocImageList.ImageStream")));

    this.chocImageList.TransparentColor = System.Drawing.Color.Transparent;

    this.Text = "Multibutton";

    }
    //construction
    public MButton()
    {
    //test 1..2..3..
    MessageBox.Show("New instance created, just a joke");
    InitializeComponent();
    }

    // create a method to display the chocolate
    private void onMyMouseHover(object sender, EventArgs ea)
    {
    this.chocolate.Show();
    MessageBox.Show("Hi there");
    MouseHover -= mouseHover;
    }

    protected override void OnMouseHover( EventArgs ea)
    {
    base.OnMouseHover(ea);
    //now call own mouse hover event
    mouseHover = new EventHandler(this.onMyMouseHover);
    this.MouseHover += mouseHover;
    }
    }
    }

  • lyubolyubo Posts: 17Member
    : Hi there, Im trying to create a button that displays a range of buttons, in this case a toolbar full of images. I use the button in an appliction and have a mouseOver methode, everything works exept for the silly chocolate doesnt show up. Any suggestions are welcome!!
    :
    : using System;
    : using System.Drawing;
    : using System.Collections;
    : using System.ComponentModel;
    : using System.Windows.Forms;
    : using System.Data;
    :
    : namespace MultiButton
    : {
    :
    : public class MButton : System.Windows.Forms.Button
    : {
    : private EventHandler mouseHover; //delegate
    : private System.Windows.Forms.Timer myTicker;
    : private System.Windows.Forms.ToolBar chocolate;
    : private System.Windows.Forms.ToolBarButton toolBarButton1;
    : private System.Windows.Forms.ToolBarButton toolBarButton2;
    :
    : private System.Windows.Forms.ImageList chocImageList;
    : private System.ComponentModel.IContainer components;
    :
    :
    : private void InitializeComponent()
    : {
    : this.components = new System.ComponentModel.Container();
    : System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MButton));
    :
    : this.chocolate = new System.Windows.Forms.ToolBar();
    :
    : this.toolBarButton1 = new System.Windows.Forms.ToolBarButton();
    :
    : this.toolBarButton2 = new System.Windows.Forms.ToolBarButton();
    :
    : this.chocImageList = new System.Windows.Forms.ImageList(this.components);
    :
    : this.chocolate.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
    : this.toolBarButton1,
    : this.toolBarButton2});
    :
    : this.chocolate.Dock = System.Windows.Forms.DockStyle.Right;
    : this.chocolate.DropDownArrows = true;
    : this.chocolate.ImageList = this.chocImageList;
    : this.chocolate.Location = new System.Drawing.Point(113, 17);
    : this.chocolate.Name = "chocolate";
    : this.chocolate.ShowToolTips = true;
    : this.chocolate.Size = new System.Drawing.Size(24, 267);
    : this.chocolate.TabIndex = 0;
    :
    : this.toolBarButton1.ImageIndex = 0;
    :
    : this.toolBarButton2.ImageIndex = 1;
    :
    : this.chocImageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
    :
    : this.chocImageList.ImageSize = new System.Drawing.Size(16, 16);
    : this.chocImageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("chocImageList.ImageStream")));
    :
    : this.chocImageList.TransparentColor = System.Drawing.Color.Transparent;
    :
    : this.Text = "Multibutton";
    :
    : }
    : //construction
    : public MButton()
    : {
    : //test 1..2..3..
    : MessageBox.Show("New instance created, just a joke");
    : InitializeComponent();
    : }
    :
    : // create a method to display the chocolate
    : private void onMyMouseHover(object sender, EventArgs ea)
    : {
    : this.chocolate.Show();
    : MessageBox.Show("Hi there");
    : MouseHover -= mouseHover;
    : }
    :
    : protected override void OnMouseHover( EventArgs ea)
    : {
    : base.OnMouseHover(ea);
    : //now call own mouse hover event
    : mouseHover = new EventHandler(this.onMyMouseHover);
    : this.MouseHover += mouseHover;
    : }
    : }
    : }
    :
    :
    // i read your code very fast, my suggestion may be wrong, but try to..
    // enable the damn control ;-)
    chocolate.Enabled=true;

Sign In or Register to comment.