Hello, on the form is located GroupBox c several RadioButton . It is necessary for the selection of the corresponding RadioButton to change the BorderStyle form. If I understand correctly, I need a CheckedChange event for the buttons, but I don’t understand how to set the border style, please tell me. Thanks.
2 answers
The easiest way is to attach your event handler to each RadioButton and set the required form frame in it.
private void radioButton1_CheckedChanged(object sender, EventArgs e) { FormBorderStyle = FormBorderStyle.FixedSingle; } private void radioButton2_CheckedChanged(object sender, EventArgs e) { FormBorderStyle = FormBorderStyle.Fixed3D; } And so on...
BorderStyle the form is actually called FormBorderStyle . Of course, it is possible to change it during the execution of the program, but only this will really give you a little, since it is not enough just to change the style of the frame, you also need to re-create the form, otherwise the specified style will not be applied as expected.
Here are my attempts in the form of a solution.
What I do (briefly): There are 7 radio buttons on the form (that is how many styles for the form are available in the designer). Each radio button has a value from 0 to 6 in the Tag property. All radio buttons use one click handler, which determines the value of the Tag property and, depending on its value, sets the style of the border of the form. Everything. There is also a second form to which the selected style is applied, but it is shown by pressing the corresponding button.
The main logic of the work is in the handler for clicking on the radio button:
void RadioButtonSelected(object sender, EventArgs e) { RadioButton rb = sender as RadioButton; int tag = -1; if (rb.Tag != null) { tag = Convert.ToInt32(rb.Tag); } switch (tag) { case 0: _style = FormBorderStyle.FixedSingle; break; case 1: _style = FormBorderStyle.FixedSingle; break; case 2: _style = FormBorderStyle.Fixed3D; break; case 3: _style = FormBorderStyle.FixedDialog; break; case 4: _style = FormBorderStyle.Sizable; break; case 5: _style = FormBorderStyle.FixedToolWindow; break; case 6: _style = FormBorderStyle.SizableToolWindow; break; default: _style = FormBorderStyle.Sizable; break; } this.FormBorderStyle = _style; this.RecreateHandle(); //Пробую пересоздать форму с новым стилем. } void Button1Click(object sender, EventArgs e) { FormDemo demo = new FormDemo(); demo.FormBorderStyle = _style; demo.ShowDialog(); } } I do not know why, but my project on Win 7 does not work the way I expected from it. Yes, the style of the frame is changing, but not fully.
- Thanks for the help) - Maxim Ustelemov