Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Clicking an invisble button
 

Clicking an invisble button

Hi, Is it possible to click an invisible button? For the application I am writing (a game)I need a button which when clicked becomes invisible and performs a function (displays an option). However the user may select not to proceed with the option and want to restore the position by clicking the original button position.

I can set the button.visible = false but cannot deselect the action by clicking again where the button was.

Can it be done?

AlanCam  Saturday, February 03, 2007 4:49 PM

after the button hide we can get button location and width and height to fire form click event

as follow, hope it help you

private void Form1_MouseClick(object sender, MouseEventArgs e)

{

int x=this.button1.Location.X;

int y = this.button1.Location.Y;

int w = this.button1.Width;

int h = this.button1.Height;

if(e.X>x&&e.X<x+w&&e.Y>y&&e.Y<y+h)

MessageBox.Show("clicked");

}

private void button1_Click(object sender, EventArgs e)

{

this.button1.Visible =false;

MessageBox.Show("clicked");

}

Bob zhu - SJTU  Monday, February 05, 2007 7:15 AM

Maybe you can do in this way:

put a picture which is like the form background,

and add click to the picture.

Regards

Gavin Jin - MSFT  Sunday, February 04, 2007 3:35 PM

after the button hide we can get button location and width and height to fire form click event

as follow, hope it help you

private void Form1_MouseClick(object sender, MouseEventArgs e)

{

int x=this.button1.Location.X;

int y = this.button1.Location.Y;

int w = this.button1.Width;

int h = this.button1.Height;

if(e.X>x&&e.X<x+w&&e.Y>y&&e.Y<y+h)

MessageBox.Show("clicked");

}

private void button1_Click(object sender, EventArgs e)

{

this.button1.Visible =false;

MessageBox.Show("clicked");

}

Bob zhu - SJTU  Monday, February 05, 2007 7:15 AM

You can use google to search for other answers

Custom Search

More Threads

• Making a custom TextBox component with a prompt button
• Dialogs inheriting from dialogs inheriting from dialogs get multiple OK events!!!
• Combining already programmed projects to one big'n
• Relating Combos on Windows Forms
• DrawGrid and SnapToGrid
• DesignSurface Problem
• Hosting Form Designer + Creating a TabControl with no TabPages
• Disappearing Tab Controls
• Designer calling the Form Load event of Base Form...
• tablelayoutpanel problem