我正在寻找一种改变窗体框周围框架的方法。我想让它透明,或完全摆脱它。我设法摆脱了图标,摆脱了最大化按钮,并限制了用户调整窗口大小的能力。酒吧与我试图实施的视觉主题发生冲突。
所以问题 - 有没有什么好方法可以自定义表格边框& Windows窗体应用程序中的顶部栏?
答案 0 :(得分:2)
为FormBorderStyle
选择正确的值,例如None
。
答案 1 :(得分:1)
对于你所要求的内容,这可能有点过分,但是这里......这是我用圆形边框创建的快速应用程序。这不是整个代码,但也许你会从中得到这个想法。
首先,我删除FormBorderStyle(将其设置为None)并添加一个鼠标处理程序以允许移动表单。代码如下......
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;
private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
然后我创建了一个粉红色网格以显示为表单背景。并将TransparencyKey属性设置为我想要透明的背景颜色的RGB值(在本例中为255,15,255)。
然后我用图形模块绘制了文字控件。
private void Form1_Paint(object sender, PaintEventArgs e)
{
// Set the starting coordinants for our graphics drawing
int y = 0;
int x = 0;
// Set the end coordinants for our graphics drawing
int width = this.Size.Width;
int height = this.Size.Height;
// Set our graphics options
e.Graphics.InterpolationMode = XGraphics.xInterpolation;
e.Graphics.SmoothingMode = XGraphics.xSmoothingMode;
e.Graphics.CompositingMode = XGraphics.xComposingMode;
e.Graphics.CompositingQuality = XGraphics.xComposingQuality;
e.Graphics.PixelOffsetMode = XGraphics.xPixelOffsetMode;
// Set the colors, positions, and gradient directions then draw our background
using (LinearGradientBrush gpxBrush = XGraphics.GradientBrushOrientation(0, x, y, width, height))
{
// Create our color blender object
ColorBlend gpxBlend = null;
gpxBlend = new ColorBlend(4);
gpxBlend.Colors = new Color[] { Color.FromArgb(255, 0, 100, 255), Color.FromArgb(205, 255, 240, 240),
Color.FromArgb(255, 20, 100, 230), Color.FromArgb(105, 105, 100, 255) };
gpxBlend.Positions = new float[] { 0.0F, .45F, .55F, 1.0F };
gpxBrush.InterpolationColors = gpxBlend;
// Draw our background
e.Graphics.FillEllipse(gpxBrush, x, y, width, height);
}
// Set the end coordinants for our graphics drawing
width = this.Size.Width-5;
height = this.Size.Height-5;
using (LinearGradientBrush gpxBrush = XGraphics.GradientBrushOrientation(0, x, y, width, height))
{
// Create our color blender object
ColorBlend gpxBlend = null;
gpxBlend = new ColorBlend(2);
gpxBlend.Colors = new Color[] { Color.White, Color.Gray };
gpxBlend.Positions = new float[] { 0.0F, 1.0F };
gpxBrush.InterpolationColors = gpxBlend;
// Draw our background
e.Graphics.FillEllipse(gpxBrush, x+5, y+5, width-5, height-5);
}
width = this.Size.Width / 2;
height = this.Size.Height / 2;
using (LinearGradientBrush gpxBrush = XGraphics.GradientBrushOrientation(0, x, y, width, height))
{
// Create our color blender object
ColorBlend gpxBlend = null;
gpxBlend = new ColorBlend(2);
gpxBlend.Colors = new Color[] { Color.White, Color.Gray };
gpxBlend.Positions = new float[] { 0.0F, 1.0F };
gpxBrush.InterpolationColors = gpxBlend;
// Draw our background
e.Graphics.FillEllipse(gpxBrush, x + width / 2, y + height / 2, width, height);
}
width = (this.Size.Width / 2) - 5;
height = (this.Size.Height / 2) - 5;
using (LinearGradientBrush gpxBrush = XGraphics.GradientBrushOrientation(0, x, y, width-5, height-5))
{
// Create our color blender object
ColorBlend gpxBlend = null;
gpxBlend = new ColorBlend(4);
gpxBlend.Colors = new Color[] { Color.FromArgb(255, 0, 100, 255), Color.FromArgb(205, 255, 240, 240),
Color.FromArgb(255, 20, 100, 230), Color.FromArgb(105, 105, 100, 255) };
gpxBlend.Positions = new float[] { 0.0F, .45F, .55F, 1.0F };
gpxBrush.InterpolationColors = gpxBlend;
// Draw our background
e.Graphics.FillEllipse(gpxBrush, (x + width / 2) +7, (y + height / 2) + 7, width - 5, height - 5);
}
}
如您所见,现在没有边框,边缘是透明的。只需确保添加一个按钮即可退出应用程序,因为不再有“X”选项了! ;)
希望这对你有所帮助!