[英]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.