가능한 한 실제 화면 크기에 관계없이
위의 두 숫자를 서로 표시하려면
으로 표시하고 싶습니다. (게다가 clumsyness)이 코드레이블 텍스트가 너무 낮게 표시됩니다.
//getting screen size and setting window to maximized
Rectangle screenEdge = Screen.PrimaryScreen.Bounds;
this.Width = screenEdge.Width;
this.Height = screenEdge.Height;
this.FormBorderStyle = FormBorderStyle.FixedToolWindow;
this.WindowState = FormWindowState.Maximized;
//using 90% of width and 40% (times two) of height
int lWidth = (int)(this.Width * 0.9);
int lHeight = (int)(this.Height * 0.4);
//horiz. spacing: remainder, divided up for left and right
int lLeft = (this.Width - lWidth)/2;
//vert. spacing: remainder divided for top, bottom and between
int lTop = (this.Height - (2 * lHeight))/3 ;
//the labels holding the numbers
lSoll = new Label();
lIst = new Label();
//setting label lSoll to calc'd dimensions, adding & aligning text
lSoll.Left = lLeft;
lSoll.Width = lWidth;
lSoll.Top = lTop;
lSoll.Height = lHeight;
Font sollFont = new Font(FontFamily.GenericSansSerif, lSoll.Height);
Font sFSized = new Font(sollFont.FontFamily, lSoll.Height);
lSoll.Font = sFSized;
lSoll.TextAlign = ContentAlignment.MiddleCenter;
lSoll.ForeColor = Color.Blue;
lSoll.BackColor = Color.White;
updateSollText(42);
//same as above, just a bit lower
lIst.Left = lLeft;
lIst.Width = lWidth;
lIst.Top = lTop * 2 + lSoll.Height;
lIst.Height = lHeight;
Font istFont = new Font(FontFamily.GenericSansSerif, lIst.Height);
Font iFSized = new Font(istFont.FontFamily, lIst.Height);
lIst.Font = iFSized;
lIst.TextAlign = ContentAlignment.TopCenter;
lIst.ForeColor = Color.Red;
lIst.BackColor = Color.White;
updateIstText(39);
문제 : 라벨
텍스트 부분적 즉 보이지 레이블의 하한, 아래에 표시되고, 바닥에서 스크린을 참조.
나는 내 계산을 두 번 확인했는데 1 포인트 (반올림)의 반올림 오류 이외에는 모두 작동해야한다는 것을 알았습니다.
필자는 글꼴 높이를 레이블 높이보다 작게 만들려고했지만 약간은 도움이되었지만 확실히 수정되지는 않았습니다.
사실 내가 textalign이 그것을 커버해야하지만, 그것이 그것이 무엇을 위해 있기 때문에 사실.
또한 왼쪽 반면, 아무것도 변경하지 않은 textAlign과의 높이 완 (낮은 중간 위) chaning/중앙/오른쪽 차이점이 원인이 될 수 무엇
예상 어떻게해야합니까?
레이블에는 다른 컨트롤과 겹치지 않도록 항상 가장자리와 글꼴 사이에 약간의 패딩이 있습니다. 코드에서 글꼴 크기를 레이블의 높이로 설정하면 마녀는 결코 적합하지 않음을 의미합니다. 글꼴을 돌려서 글꼴의 높이를 계산하고 레이블의 autoEllipsis 속성을 true로 설정하면 텍스트에 자동 크기 조절이 적용되지 않는 이유는 무엇입니까? 서식의 전체 너비를 포함 시키려면 레이블의 너비를 직접 변경해야합니다. –