C# How do I create code to set a form back to default properties, with a button click event? -


Using the Visual C # 2008 Express Edition, I'm trying to set a button on my form to set the form back to the default property,

size, backcolor, etc. ... does anyone have an example of how I do this?

The easiest way to do so is to create a new example of the form and close the old one . This is the main form of your app, the program requires little surgery when it is closed. Start by opening Program.c and edit it so that it looks like this:

  Fixed class program {[STAThread] static zero main () {Application.EnableVisualStyles (); Application.SetCompatibleTextRenderingDefault (wrong); AppContext = New ApplicationContext (); AppContext.MainForm = New Form 1 (); Application.Run (AppContext); } Public Fixed AppContext AppContext; }  

ApplicationContext variable now controls the life of the app instead of Form1 example. You can recreate the form with this type of code with the form:

  Private Zero Button 1_Click (Object Sender, EventArgs e) {Form1 frm = new Form1 (); Frm.StartPosition = FormStartPosition.Manual; Frm.Location = this.Location; Frm.Size = this.Size; Program. AppContext.MainForm = frm; Frm.Show (); This.Close (); }  

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -