簡體   English   中英

WPF從進度條獲取Rectangle控制范圍

[英]WPF get Rectangle control bounds from progressbar

這肯定是一個非常討厭的問題,所以請不要太刻薄地評價我! 在Windows窗體應用程序中,類似以下內容很容易獲得進度條的限制:

progressBar1.Bounds.X(or)Y

如何在WPF中獲得相同的信息? 我在互聯網上找不到任何東西。 這是我的Windows窗體應用程序的progressbar OnClick方法:

private void progressBar1_MouseClick(object sender, MouseEventArgs e)
{
    float absoluteMouse = (PointToClient(MousePosition).X - progressBar1.Bounds.X);
    float calcFactor = progressBar1.Width / (float)100;
    float relativeMouse = absoluteMouse / calcFactor;
    double maxlength = BASS_ChannelBytes2Seconds(BassHandle, (ulong)PlayBackLength);
    double percents = (maxlength * relativeMouse) / 100;
    UInt64 pos = BASS_ChannelSeconds2Bytes(BassHandle, percents);
    BASS_ChannelSetPosition(BassHandle, pos, 0);
    progressBar1.Value = Convert.ToInt32(relativeMouse);
    int current = BASS_ChannelGetPosition(BassHandle, 0);
    TimeLabel.Text = FormatTime(BASS_ChannelBytes2Seconds(BassHandle, (uint)current)) + "/" + FormatTime(BASS_ChannelBytes2Seconds(BassHandle, (uint)PlayBackLength));
}

這是我嘗試的WPF版本

private void progressBar1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{

    double absoluteMouse = (PointFromScreen(GetMousePosition()).X - progressBar1.?);
    double calcFactor = progressBar1.Width / (float)100;
    double relativeMouse = absoluteMouse / calcFactor;
    double maxlength = Imports.BASS_ChannelBytes2Seconds(GlobalVariables.BassHandle, (ulong)GlobalVariables.PlayBackLength);
    double percents = (maxlength * relativeMouse) / 100;
    UInt64 pos = Imports.BASS_ChannelSeconds2Bytes(GlobalVariables.BassHandle, percents);
    Imports.BASS_ChannelSetPosition(GlobalVariables.BassHandle, pos, 0);
    progressBar1.Value = Convert.ToInt32(relativeMouse);
    int current = Imports.BASS_ChannelGetPosition(GlobalVariables.BassHandle, 0);
    TimeLabel.Text = FormatTime(Imports.BASS_ChannelBytes2Seconds(GlobalVariables.BassHandle, (uint)current)) + "/" + FormatTime(Imports.BASS_ChannelBytes2Seconds(GlobalVariables.BassHandle, (uint)GlobalVariables.PlayBackLength));
}

您可以使用progressBar1.Margin.Left-表示X,使用progressBar1.Margin.Top-Y表示。但是相對於放置ProgressBar的Container而言,會有一些值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM