【发布时间】:2016-05-11 01:59:09
【问题描述】:
这一定是一个非常菜鸟的问题,所以请不要过分评价我! 在 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));
}
【问题讨论】:
标签: c# wpf winforms progress-bar rect