작업 표시 줄 상단에 Windows Form을 전체 화면으로 표시하는 방법은 무엇입니까?
이 질문에 이미 답변이 있습니다.
전체 화면에서 실행해야하는 .net Windows 응용 프로그램이 있습니다. 그러나 응용 프로그램이 시작되면 작업 표시 줄이 기본 양식 상단에 표시하고 양식을 클릭하거나 Alt-Tab을 사용하여 양식을 활성화 할 때만 사라집니다. 양식의 현재 속성은 다음과 가변합니다.
- WindowState = FormWindowState.Normal
- TopMost = 보통
- 크기 = 1024,768 (이는 실행될 컴퓨터의 화면 해상도)
- FormBorderStyle = 없음
시도로드에 다음을 시도하려고 시도했지만 효과가 없었습니다.
- this.Focus (); (초점을 부여한 후 this.Focus 속성은 항상 false입니다)
- this.BringToFront ();
- this.TopMost = true; (그러나 이것은 내 시나리오에서 시나리오이지)
- this.Bounds = Screen.PrimaryScreen.Bounds;
- this.Bounds = Screen.PrimaryScreen.Bounds;
.NET 내에서 수행 할 수있는 방법이 아니면 수행 할 수있는 방법이 있습니까? 조각이 매우 감사하겠습니다.
많은 감사
사용하다 :
FormBorderStyle = FormBorderStyle.None;
WindowState = FormWindowState.Maximized;
그런 다음 양식이 작업 표시 줄 위에 배치됩니다.
나는 너무 많은 솔루션을 시도해 브라이 들고, 그들 중 일부는 Windows XP에서 작동하고 그들 모두는 Windows 7에서 작동하지 않습니다. 결국 나는 그렇게하는 간단한 방법을 작성했습니다.
private void GoFullscreen(bool fullscreen)
{
if (fullscreen)
{
this.WindowState = FormWindowState.Normal;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Bounds = Screen.PrimaryScreen.Bounds;
}
else
{
this.WindowState = FormWindowState.Maximized;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
}
}
코드 순서는 중요하며 WindwosState 및 FormBorderStyle의 위치를 변경하면 작동하지 않습니다.
이 방법의 장점 중 하나는 TOPMOST를 거짓으로 두어 다른 양식이 기본 양식에 오도록 허용한다는 것입니다.
그것은 내 문제를 절대적으로 해결했습니다.
이것이 내가 양식을 전체 화면으로 만드는 방법입니다.
private void button1_Click(object sender, EventArgs e)
{
int minx, miny, maxx, maxy;
inx = miny = int.MaxValue;
maxx = maxy = int.MinValue;
foreach (Screen screen in Screen.AllScreens)
{
var bounds = screen.Bounds;
minx = Math.Min(minx, bounds.X);
miny = Math.Min(miny, bounds.Y);
maxx = Math.Max(maxx, bounds.Right);
maxy = Math.Max(maxy, bounds.Bottom);
}
Form3 fs = new Form3();
fs.Activate();
Rectangle tempRect = new Rectangle(1, 0, maxx, maxy);
this.DesktopBounds = tempRect;
}
내 간단한 수정은 양식의 메소드 Activate()
를 호출하는 것으로 판명은 신뢰할 수 없습니다 TopMost
.
FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
WindowState = FormWindowState.Maximized;
테스트되고 간단한 솔루션
나는 SO와 다른 사이트 에서이 질문에 대한 답을 찾고 있었지만 하나의 대답이 나에게 매우 많았지 만 하나의 대답이 나에게 매우 많은 코드 테스트 후이 퍼즐을 해결했습니다.
참고 : Windows 8을 사용하는 중이고 작업 아닙니다.
수정을 수행하기 전에 WindowState를 Normal로 설정하면 적용되지 않는 작업 표시가 있습니다.
코드
첫 번째는 "전체 화면 모드"로 내용 고 두 번째는 "전체 화면 모드"에서 나가는 두 가지 메소드가있는이 클래스를 만들었습니다. 따라서이 클래스의 개체를 생성하여 전체 화면으로 설정하려는 양식을 EnterFullScreenMode 메서드 또는 LeaveFullScreenMode 메서드에 대한 인수로 전달하면됩니다.
class FullScreen
{
public void EnterFullScreenMode(Form targetForm)
{
targetForm.WindowState = FormWindowState.Normal;
targetForm.FormBorderStyle = FormBorderStyle.None;
targetForm.WindowState = FormWindowState.Maximized;
}
public void LeaveFullScreenMode(Form targetForm)
{
targetForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
targetForm.WindowState = FormWindowState.Normal;
}
}
사용 예
private void fullScreenToolStripMenuItem_Click(object sender, EventArgs e)
{
FullScreen fullScreen = new FullScreen();
if (fullScreenMode == FullScreenMode.No) // FullScreenMode is an enum
{
fullScreen.EnterFullScreenMode(this);
fullScreenMode = FullScreenMode.Yes;
}
else
{
fullScreen.LeaveFullScreenMode(this);
fullScreenMode = FullScreenMode.No;
}
}
나는이 질문의 두인지 아닌지 확실하지 않은 다른 질문 에이 동일한 답변을 배치했습니다. (다른 질문에 대한 링크 : WinForms 앱을 전체 화면으로 만드는 방법 )
FormBorderStyle 속성을 None으로 설정하고 WindowState를 Maximized로 설정하면 가능하다고 생각합니다. Visual Studio를 사용하는 경우 두 가지 모두 IDE에서 찾을 수 있으므로 프로그래밍 방식으로 수행 할 필요가 없습니다. 이 작업을 수행하기 전에 프로그램을 종료 / 종료하는 방법을 포함해야합니다. 이렇게하면 오른쪽 상단 모서리에있는 유용한 X가 제거됩니다.
편집하다:
대신 이것을 시도하십시오. 오랫동안 간직해온 스 니펫입니다. 나는 그것을 누구에게 인정해야하는지조차 기억할 수 없지만 작동합니다.
/*
* A function to put a System.Windows.Forms.Form in fullscreen mode
* Author: Danny Battison
* Contact: gabehabe@googlemail.com
*/
// a struct containing important information about the state to restore to
struct clientRect
{
public Point location;
public int width;
public int height;
};
// this should be in the scope your class
clientRect restore;
bool fullscreen = false;
/// <summary>
/// Makes the form either fullscreen, or restores it to it's original size/location
/// </summary>
void Fullscreen()
{
if (fullscreen == false)
{
this.restore.location = this.Location;
this.restore.width = this.Width;
this.restore.height = this.Height;
this.TopMost = true;
this.Location = new Point(0,0);
this.FormBorderStyle = FormBorderStyle.None;
this.Width = Screen.PrimaryScreen.Bounds.Width;
this.Height = Screen.PrimaryScreen.Bounds.Height;
}
else
{
this.TopMost = false;
this.Location = this.restore.location;
this.Width = this.restore.width;
this.Height = this.restore.height;
// these are the two variables you may wish to change, depending
// on the design of your form (WindowState and FormBorderStyle)
this.WindowState = FormWindowState.Normal;
this.FormBorderStyle = FormBorderStyle.Sizable;
}
}
나는 그것이 어떻게 작동하는지에 대한 설명이 없지만 작동하며 카우보이 코더가되는 것이 내가 필요한 전부입니다.
System.Drawing.Rectangle rect = Screen.GetWorkingArea(this);
this.MaximizedBounds = Screen.GetWorkingArea(this);
this.WindowState = FormWindowState.Maximized;
FormBorderStyle = FormBorderStyle.Sizable;
TopMost = false;
WindowState = FormWindowState.Normal;
이 코드는 WINDOWS를 전체 화면으로 만듭니다.이 코드는 전체 화면도 포함합니다.
'ProgramingTip' 카테고리의 다른 글
mysql 함수의 영숫자 텍스트에서 선행 0을 자르는 방법 (0) | 2020.11.29 |
---|---|
동일한 파일에 여러 클래스를 사용하는 것이 나쁜 습관입니까? (0) | 2020.11.29 |
MySQL Workbench에서 Blob을 직접 보는 방법 (0) | 2020.11.29 |
Android- 문자열의 일부를 다른 URL로 바꾸는 방법은 무엇입니까? (0) | 2020.11.29 |
편리한 정수 비교 기능 (0) | 2020.11.29 |