Questo argomento non è stato ancora valutato - Valuta questo argomento

Proprietà ToolBarButton.PartialPush

Ottiene o imposta un valore che indica se un pulsante interruttore è parzialmente premuto.

Spazio dei nomi: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public bool PartialPush { get; set; }
/** @property */
public boolean get_PartialPush ()

/** @property */
public void set_PartialPush (boolean value)

public function get PartialPush () : boolean

public function set PartialPush (value : boolean)

Valore proprietà

true se un pulsante interruttore della barra degli strumenti è parzialmente premuto; in caso contrario, false. Il valore predefinito è false.

Quando PartialPush è impostata su true, il pulsante della barra degli strumenti non sarà selezionabile. L'aspetto è diverso da quello inattivo ottenuto quando la proprietà Enabled è impostata su false, in quanto coinvolge l'intera superficie del pulsante. La proprietà ha effetto soltanto se ToolBarButtonStyle è impostato su ToggleButton.

Nell'esempio di codice riportato di seguito viene illustrato come utilizzare le proprietà Pushed e PartialPush. Per eseguire l'esempio, incollare il codice riportato di seguito in un form contenente un controllo RichTextBox denominato RichTextBox1 e chiamare il metodo InitializeToolBar dal costruttore del form o dal metodo Load.


// Declare ToolBar1.
internal System.Windows.Forms.ToolBar ToolBar1;

// Initialize ToolBar1 with Bold(B), Italic(I), and 
// Underline(U) buttons.
private void InitializeToolBar()
{
    ToolBar1 = new ToolBar();

    // Set the appearance to Flat.
    ToolBar1.Appearance = ToolBarAppearance.Flat;

    // Set the toolbar to dock at the bottom of the form.
    ToolBar1.Dock = DockStyle.Bottom;

    // Set the toolbar font to 14 points and bold.
    ToolBar1.Font = new Font(FontFamily.GenericSansSerif,
        14, FontStyle.Bold);

    // Declare fontstyle array with the three font styles.
    FontStyle[] fonts = new FontStyle[]{FontStyle.Bold, 
        FontStyle.Italic, FontStyle.Underline};
    
    int count;

    // Create a button for each value in the array, setting its 
    // text to the first letter of the style and its 
    // button's tag property.
    for(count=0; count<fonts.Length; count++)
    {
        ToolBarButton fontButton = 
            new ToolBarButton(fonts[count].ToString().Substring(0, 1));
        fontButton.Style = ToolBarButtonStyle.ToggleButton;
        fontButton.Tag = fonts[count];
        ToolBar1.Buttons.Add(fontButton);
    }
    this.ToolBar1.ButtonClick += 
        new ToolBarButtonClickEventHandler(ToolBar1_ButtonClick);
    this.Controls.Add(this.ToolBar1);
}


// Declare FontStyle object, which defaults to the Regular
// FontStyle.
FontStyle style = new FontStyle();

private void ToolBar1_ButtonClick(object sender, 
    System.Windows.Forms.ToolBarButtonClickEventArgs e)
{

    // If a button is pushed, use a bitwise Or combination 
    // of the style variable and the button tag, to set style to 
    // the correct FontStyle. Set the button's PartialPush 
    // property to true for a Windows XP-like appearance.
    if (e.Button.Pushed)
    {
        e.Button.PartialPush = true;
        style = style |(FontStyle) e.Button.Tag;

    }
    else
    {
        // If the button was not pushed, use a bitwise XOR 
        // combination to turn off that style 
        // and set the PartialPush property to false.
        e.Button.PartialPush = false;
        style = style ^ (FontStyle) e.Button.Tag;
    }

    // Set the font using the existing RichTextBox font and the new
    // style.
    RichTextBox1.Font = new Font(RichTextBox1.Font, style);

}

// Declare ToolBar1.
System.Windows.Forms.ToolBar toolBar1;

// Initialize ToolBar1 with Bold(B), Italic(I), and 
// Underline(U) buttons.
private void InitializeToolBar()
{
    toolBar1 = new ToolBar();
    // Set the appearance to Flat.
    toolBar1.set_Appearance(ToolBarAppearance.Flat);
    // Set the toolbar to dock at the bottom of the form.
    toolBar1.set_Dock(DockStyle.Bottom);
    // Set the toolbar font to 14 points and bold.
    toolBar1.set_Font(new Font(FontFamily.get_GenericSansSerif(), 14,
        FontStyle.Bold));
    // Declare fontstyle array with the three font styles.
    FontStyle fonts[] = new FontStyle[] { FontStyle.Bold, FontStyle.Italic,
        FontStyle.Underline };

    int count;
    // Create a button for each value in the array, setting its 
    // text to the first letter of the style and its 
    // button's tag property.
    for (count = 0; count < fonts.length; count++) {
        ToolBarButton fontButton = new ToolBarButton(fonts.get_Item(count).
            ToString().Substring(0, 1));
        fontButton.set_Style(ToolBarButtonStyle.ToggleButton);
        fontButton.set_Tag(fonts.get_Item(count));
        toolBar1.get_Buttons().Add(fontButton);
    }
    this.toolBar1.add_ButtonClick(new ToolBarButtonClickEventHandler(
        toolBar1_ButtonClick));
    this.get_Controls().Add(this.toolBar1);
} //InitializeToolBar

// Declare FontStyle object, which defaults to the Regular
// FontStyle.
private FontStyle style;

private void toolBar1_ButtonClick(Object sender,
    System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
    // If a button is pushed, use a bitwise Or combination 
    // of the style variable and the button tag, to set style to 
    // the correct FontStyle. Set the button's PartialPush 
    // property to true for a Windows XP-like appearance.
    if (e.get_Button().get_Pushed()) {
        e.get_Button().set_PartialPush(true);
        style = style | ( FontStyle)e.get_Button().get_Tag();
    }
    else {
        // If the button was not pushed, use a bitwise XOR 
        // combination to turn off that style 
        // and set the PartialPush property to false.
        e.get_Button().set_PartialPush(false);
        style = style ^ (FontStyle)e.get_Button().get_Tag();
    }
    // Set the font using the existing RichTextBox font and the new
    // style.
    richTextBox1.set_Font(new Font(richTextBox1.get_Font(), style));
} //toolBar1_ButtonClick 

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile per Pocket PC, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework non supporta tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema.

.NET Framework

Supportato in: 2.0 1.1 1.0
Il documento è risultato utile?
(1500 caratteri rimanenti)

Aggiunte alla community

AGGIUNGI
Microsoft sta conducendo un sondaggio in linea per comprendere l'opinione degli utenti in merito al sito Web di MSDN. Se si sceglie di partecipare, quando si lascia il sito Web di MSDN verrà visualizzato il sondaggio in linea.

Si desidera partecipare?
© 2013 Microsoft. Tutti i diritti riservati.