WPF从进度条获取Rectangle控件边界

时间:2016-05-11 01:59:09

标签: c# wpf winforms progress-bar rect

这一定是一个非常noobie的问题,所以请不要太难评判我! 在Windows窗体应用程序中,这样的东西很容易得到进度条的界限:

progressBar1.Bounds.X(or)Y

如何在WPF中获得相同的内容?我在网上找不到任何相关内容。 这是Windows窗体应用的进度条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));
}

1 个答案:

答案 0 :(得分:1)

您可以使用progressBar1.Margin.Left - 对于X,progressBar1.Margin.Top - 对于Y. 但是相对于放置ProgressBar的Container会有价值。

相关问题