logo search
Учебник_ПОА

Создание группы переключателей из массива строк

В этом примере программно создается группа элементов управления RadioButton Windows Forms и их свойствам Text присваиваются значения из массива строк.

Компиляция кода

Для этого примера необходимы следующие компоненты.

Пример

<--------

How to: Create a Non-Rectangular Button

This example demonstrates how to create a button that is a different shape from the standard rectangular button. The code adds a button in the shape of a circle to the form and creates an event handler that displays a message when the circle is clicked.

Compiling the Code

This example requires a Windows Forms Application project that contains a form named Form2.

Example

public Form2()

{

//

// Required for Windows Form Designer support.

//

InitializeComponent();

// Initialize the user-defined button,

// including defining handler for Click message,

// location and size.

myButtonObject myButton = new myButtonObject();

EventHandler myHandler =

new EventHandler(myButton_Click);

myButton.Click += myHandler;

myButton.Location = new System.Drawing.Point(20, 20);

myButton.Size = new System.Drawing.Size(101, 101);

this.Controls.Add(myButton);

}

public class myButtonObject : UserControl

{

// Draw the new button.

protected override void OnPaint(PaintEventArgs e)

{

Graphics graphics = e.Graphics;

Pen myPen = new Pen(Color.Black);

// Draw the button in the form of a circle

graphics.DrawEllipse(myPen, 0, 0, 100, 100);

myPen.Dispose();

}

}

// Handler for the click message.

void myButton_Click(Object sender, System.EventArgs e)

{

MessageBox.Show("Click");

}