本文介绍了矩形与控件的对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新年快乐。希望每个人都享受假期!



我安装了一个我在Visual Studio C#中开发的应用程序,在一些具有更高分辨率屏幕的新笔记本电脑上并将它们发送到现场。一切正常,但有以下异常。此应用程序的关键组件是在客户站点上花费的时间。它以15分钟为增量输入。为了帮助员工输入时间,我使用无线电控件并在控件下方的图形栏中显示隐含时间。这是一个糟糕的屏幕表示(因为我不能粘贴图像)。图像'X'是图形彩色矩形。以下是3:00到4:15的正确表示。



 1 2 3 4 5 6 7 
ooooooo
XXXXXX





当在其中一台新笔记本电脑上输入相同的数据时,矩形不再与正确的无线电控制。



 1 2 3 4 5 6 7 
ooooooo
XXXXXX







时间分为24小时,增量为15分钟。矩形的颜色由代码中较早初始化的数组中的条目控制。根据无线电控制位置属性中的x,y坐标,无线电控制器相隔20个单位。所以我使矩形的宽度= 5(20/4十五分钟段)并计算左侧位置。



所以问题是:为什么这对旧笔记本电脑起作用,无论我在屏幕上设置什么分辨率,都可以在我的开发PC上运行,但是没有正确对齐新的笔记本电脑?



矩形r = 矩形( 2  2  20  10 );  //   left,top,width,heigth  
int width = 5 ;
int top = 2 ;
int height = 10 ;
位图bmp = 位图(hourlyPictureBox.Width,hourlyPictureBox.Height);
Graphics g = Graphics.FromImage(bmp);
g.PageUnit = GraphicsUnit.Pixel;
for (i = 0 ; i < ; = 100 ; i ++)
{
r = new 矩形( 4 +(i * width),top,width,height); // left,top,width,heigth
if (slot [i] == 0
{
g.FillRectangle(Brushes.White,r);
}
如果(slot [i] == 1
{
g.FillRectangle(Brushes.red,r);
}
........等等 所有颜色$​​ b $ b}



hourlyPictureBox.Image = bmp;

希望对于知道自己在做什么的人来说这是一个简单的问题。 :=)

提前感谢您对此事的帮助。

Rob



添加了代码块 - OriginalGriff [/ edit]

解决方案




Happy New Year. Hope everyone enjoyed the holidays !

I installed an application I developed in Visual Studio C# on some new laptops with wider higher resolution screens and sent them into the field. Everything works fine with the following exception. A key component to this application is the entry of time spent on customer sites. It is entered in 15 minute increments. To aid the employee in entering the time I use radio controls and display the implied time in a graphic bar below the controls. Here is a poor representation to the screen (since I cant paste an image here). Image the 'X' are a graphic colored rectangle. The following is a correct representation of 3:00 to 4:15.

1   2   3   4   5   6   7
o   o   o   o   o   o   o
        XXXXXX



When the same data is entered on one of the new laptops the rectangles no longer align with the correct radio controls.

1   2   3   4   5   6   7
o   o   o   o   o   o   o
   XXXXXX




The time is split into 24 hours in 15 minute increments. The color of the rectangle is controlled by an entry in an array initialized earlier in the code. The Radio controls are located 20 units apart according the x,y coordinates in the radio control location property. So I make the width of the rectangle = 5 (20/4 fifteen minute segments) and calculate the left position.

So the question is: Why does this work on the old laptops, works on my development PC regardless of what resolution I set the screen, but does NOT align properly on the new laptops?

Rectangle r = new Rectangle(2, 2, 20, 10); //left,top,width,heigth
int width = 5;
int top = 2;
int height = 10;
Bitmap bmp = new Bitmap(hourlyPictureBox.Width, hourlyPictureBox.Height);
Graphics g = Graphics.FromImage(bmp);
g.PageUnit = GraphicsUnit.Pixel;
for (i = 0; i <= 100; i++)
   {
    r = new Rectangle(4 + (i * width), top, width, height); //left,top,width,heigth
   if (slot[i] == 0)
    {
          g.FillRectangle(Brushes.White, r);
     }
   if (slot[i] == 1)
    {
          g.FillRectangle(Brushes.red, r);
     }
      ........so on and so forth for all the colors
   }


hourlyPictureBox.Image = bmp;
Hopefully a simple question for someone who knows what they are doing. :=)
Thank you in advance for your help in this matter.
Rob

[edit]Code blocks added - OriginalGriff[/edit]

解决方案




这篇关于矩形与控件的对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 00:30