Este artigo foi traduzido por máquina. Coloque o ponteiro do mouse sobre as frases do artigo para ver o texto original. Mais informações. |
Tradução
Original
|
Classe RadioButtonRenderer
Fornece métodos usados para processar um controle de botão de opção (também conhecido sistema autônomo um botão de opção) com ou sem estilos visuais. Esta classe não pode ser herdada.
Assembly: System.Windows.Forms (em System.Windows.Forms.dll)
The RadioButtonRenderer classe fornece um conjunto de static métodos que podem ser usados para processar um controle de botão de opção. Processar um controle refere-se a interface de usuário de um controle de desenho. Para desenhar um botão de opção, use um do DrawRadioButton métodos. Esses métodos fornecem uma variedade de opções, sistema autônomo o texto do desenho ou uma imagem com o botão de opção.
Se estilos visuais estiverem habilitados no sistema operacional e estilos visuais são aplicados ao aplicativo corrente, DrawRadioButton desenhará o botão de opção com o estilo visual corrente. Caso contrário, DrawRadioButton desenhará o botão de opção com o estilo clássico do Windows. Isso é útil se você está desenhando um controle personalizado que automaticamente deve corresponder a configuração de estilo visual corrente do sistema operacional.
Essa classe encapsula a funcionalidade de um System.Windows.Forms.VisualStyles.VisualStyleRenderer que é definido como um dos elementos expostos pela System.Windows.Forms.VisualStyles.VisualStyleElement.Button.RadioButton classe. Para mais informação, veja Controles de processamento com estilos visuais.
Windows XP Home Edition, Windows XP Professional x64 Edition, Windows Server 2003 Observação Zoom, Para Cima e Ampliar:
Só há suporte para estilos visuais nessas plataformas.
O exemplo de código a seguir demonstra como gravar um controle personalizado que usa o DrawRadioButton método para desenhar um botão de opção que responde a cliques de mouse.
using System; using System.Drawing; using System.Windows.Forms; using System.Windows.Forms.VisualStyles; namespace RadioButtonRendererSample { class Form1 : Form { Button button1 = new Button(); public Form1() : base() { CustomRadioButton RadioButton1 = new CustomRadioButton(); button1.Location = new System.Drawing.Point(175, 231); button1.Size = new System.Drawing.Size(105, 23); button1.Text = "Toggle Style"; button1.Click += new System.EventHandler(this.button1_Click); Controls.Add(RadioButton1); Controls.Add(button1); if (Application.RenderWithVisualStyles) this.Text = "Visual Styles Enabled"; elsethis.Text = "Visual Styles Disabled"; } [STAThread] staticvoid Main() { // If you do not call EnableVisualStyles below, then // RadioButtonRenderer.DrawRadioButton automatically detects // this and draws the radio button without visual styles. Application.EnableVisualStyles(); Application.Run(new Form1()); } privatevoid button1_Click(object sender, EventArgs e) { Application.VisualStyleState = Application.VisualStyleState ^ VisualStyleState.ClientAndNonClientAreasEnabled; GroupBoxRenderer.RenderMatchingApplicationState = true; if (Application.RenderWithVisualStyles) this.Text = "Visual Styles Enabled"; elsethis.Text = "Visual Styles Disabled"; } } publicclass CustomRadioButton : Control { private Rectangle textRectangleValue = new Rectangle(); privatebool clicked = false; private RadioButtonState state = RadioButtonState.UncheckedNormal; public CustomRadioButton() : base() { this.Location = new Point(50, 50); this.Size = new Size(100, 20); this.Text = "Click here"; this.Font = SystemFonts.IconTitleFont; } // Define the text bounds so that the text rectangle // does not include the radio button.public Rectangle TextRectangle { get { using (Graphics g = this.CreateGraphics()) { textRectangleValue.X = ClientRectangle.X + RadioButtonRenderer.GetGlyphSize(g, RadioButtonState.UncheckedNormal).Width; textRectangleValue.Y = ClientRectangle.Y; textRectangleValue.Width = ClientRectangle.Width - RadioButtonRenderer.GetGlyphSize(g, RadioButtonState.UncheckedNormal).Width; textRectangleValue.Height = ClientRectangle.Height; } return textRectangleValue; } } // Draw the radio button in the current state.protectedoverridevoid OnPaint(PaintEventArgs e) { base.OnPaint(e); RadioButtonRenderer.DrawRadioButton(e.Graphics, ClientRectangle.Location, TextRectangle, this.Text, this.Font, clicked, state); } // Draw the radio button in the checked or unchecked state.protectedoverridevoid OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); if (!clicked) { clicked = true; this.Text = "Clicked!"; state = RadioButtonState.CheckedPressed; Invalidate(); } else { clicked = false; this.Text = "Click here"; state = RadioButtonState.UncheckedNormal; Invalidate(); } } // Draw the radio button in the hot state.protectedoverridevoid OnMouseHover(EventArgs e) { base.OnMouseHover(e); state = clicked ? RadioButtonState.CheckedHot : RadioButtonState.UncheckedHot; Invalidate(); } // Draw the radio button in the hot state.protectedoverridevoid OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); this.OnMouseHover(e); } // Draw the radio button in the unpressed state.protectedoverridevoid OnMouseLeave(EventArgs e) { base.OnMouseLeave(e); state = clicked ? RadioButtonState.CheckedNormal : RadioButtonState.UncheckedNormal; Invalidate(); } } }
Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
o.NET Framework e.NET Compact Framework não oferecem suporte a todas as versões de cada plataforma. Para obter uma lista de versões suportadas, consulte Requisitos de sistema do .NET framework.