TrackBarRenderer.GetTopPointingThumbSize(Graphics, TrackBarThumbState) Metoda
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
Vrátí velikost posuvníku track baru (označovaného také jako palec) v pixelech, který ukazuje nahoru.
public:
static System::Drawing::Size GetTopPointingThumbSize(System::Drawing::Graphics ^ g, System::Windows::Forms::VisualStyles::TrackBarThumbState state);
public static System.Drawing.Size GetTopPointingThumbSize(System.Drawing.Graphics g, System.Windows.Forms.VisualStyles.TrackBarThumbState state);
static member GetTopPointingThumbSize : System.Drawing.Graphics * System.Windows.Forms.VisualStyles.TrackBarThumbState -> System.Drawing.Size
Public Shared Function GetTopPointingThumbSize (g As Graphics, state As TrackBarThumbState) As Size
Parametry
- state
- TrackBarThumbState
Jedna z TrackBarThumbState hodnot, která určuje vizuální stav posuvníku.
Návraty
Určuje Size velikost posuvníku v pixelech.
Výjimky
Operační systém nepodporuje vizuální styly.
nebo
Vizuální styly jsou zakázány uživatelem v operačním systému.
nebo
Styly vizuálů se nepoužívají v klientské oblasti oken aplikací.
Příklady
Následující příklad kódu používá metodu GetTopPointingThumbSize k určení velikosti obdélníku používané metodou DrawTopPointingThumb kreslení posuvníku. Tento příklad kódu je součástí většího příkladu uvedeného pro třídu TrackBarRenderer.
// Calculate the sizes of the bar, thumb, and ticks rectangle.
private:
void SetupTrackBar()
{
if (!TrackBarRenderer::IsSupported)
{
return;
}
Graphics^ g = this->CreateGraphics();
// Calculate the size of the track bar.
trackRectangle.X = ClientRectangle.X + 2;
trackRectangle.Y = ClientRectangle.Y + 28;
trackRectangle.Width = ClientRectangle.Width - 4;
trackRectangle.Height = 4;
// Calculate the size of the rectangle in which to
// draw the ticks.
ticksRectangle.X = trackRectangle.X + 4;
ticksRectangle.Y = trackRectangle.Y - 8;
ticksRectangle.Width = trackRectangle.Width - 8;
ticksRectangle.Height = 4;
tickSpace = ((float)ticksRectangle.Width - 1) /
((float)numberTicks - 1);
// Calculate the size of the thumb.
thumbRectangle.Size =
TrackBarRenderer::GetTopPointingThumbSize(g,
TrackBarThumbState::Normal);
thumbRectangle.X = CurrentTickXCoordinate();
thumbRectangle.Y = trackRectangle.Y - 8;
}
// Calculate the sizes of the bar, thumb, and ticks rectangle.
private void SetupTrackBar()
{
if (!TrackBarRenderer.IsSupported)
return;
using (Graphics g = this.CreateGraphics())
{
// Calculate the size of the track bar.
trackRectangle.X = ClientRectangle.X + 2;
trackRectangle.Y = ClientRectangle.Y + 28;
trackRectangle.Width = ClientRectangle.Width - 4;
trackRectangle.Height = 4;
// Calculate the size of the rectangle in which to
// draw the ticks.
ticksRectangle.X = trackRectangle.X + 4;
ticksRectangle.Y = trackRectangle.Y - 8;
ticksRectangle.Width = trackRectangle.Width - 8;
ticksRectangle.Height = 4;
tickSpace = ((float)ticksRectangle.Width - 1) /
((float)numberTicks - 1);
// Calculate the size of the thumb.
thumbRectangle.Size =
TrackBarRenderer.GetTopPointingThumbSize(g,
TrackBarThumbState.Normal);
thumbRectangle.X = CurrentTickXCoordinate();
thumbRectangle.Y = trackRectangle.Y - 8;
}
}
' Calculate the sizes of the bar, thumb, and ticks rectangle.
Private Sub SetupTrackBar()
If Not TrackBarRenderer.IsSupported Then
Return
End If
Using g As Graphics = Me.CreateGraphics()
' Calculate the size of the track bar.
trackRectangle.X = ClientRectangle.X + 2
trackRectangle.Y = ClientRectangle.Y + 28
trackRectangle.Width = ClientRectangle.Width - 4
trackRectangle.Height = 4
' Calculate the size of the rectangle in which to
' draw the ticks.
ticksRectangle.X = trackRectangle.X + 4
ticksRectangle.Y = trackRectangle.Y - 8
ticksRectangle.Width = trackRectangle.Width - 8
ticksRectangle.Height = 4
tickSpace = (CSng(ticksRectangle.Width) - 1) / _
(CSng(numberTicks) - 1)
' Calculate the size of the thumb.
thumbRectangle.Size = _
TrackBarRenderer.GetTopPointingThumbSize( _
g, TrackBarThumbState.Normal)
thumbRectangle.X = CurrentTickXCoordinate()
thumbRectangle.Y = trackRectangle.Y - 8
End Using
End Sub
Poznámky
Velikost posuvníku je určena aktuálním vizuálním stylem operačního systému.
Před voláním této metody byste měli ověřit, zda je truehodnota IsSupported vlastnosti .