表单背景颜色或图像卡为白色
一周前我开始自学 C#。我首先编写俄罗斯方块来熟悉这门语言。我通过在预先确定大小的位图上绘画并将其显示在图片框中(当时与窗口大小相同)来实现主要的游戏机制。现在我已经扩大了窗口大小,并开始在图片框的侧面添加其他控件。
问题是,现在我已经扩展了窗口,显示了表单背景,背景颜色永久为白色,或者我在底角看到了奇怪的白色到黑色褪色的外观。
我尝试过几件事:
- 手动设置表单背景色,但仅反映在标签上
- 检查透明度键是否为空
- 将透明度键设置为未使用的颜色,没有任何变化
- 添加了bmp作为表单的背景图像,仍然保持白色
- 检查我的代码,看看我是否每次都直接写入表单背景,
我不知道如何解决这个问题;有人有什么想法吗?
编辑:
我找到了问题的答案。在我的构造函数中调用了 SetStyle(ControlStyles.Opaque, true) 。我不确定这到底是做什么的,但我将其注释掉并解决了我的问题。
I started teaching myself C# a week ago. I started by writing Tetris to get myself acquainted with the language. I got the main game mechanics working by painting onto presized bitmap and displaying it in a picturebox, which at the time was the same size of the window. Now I have expanded the windows size and started adding other controls to the side of the picture box.
The problem is, now that I have expanded the window, displaying the form background, the background color is permanently white or I get a weird white to black faded look in the bottom corner.
I have tried several things:
- set the form backcolor manually, but it is only reflected on the labels
- checked that the transparencykey is empty
- set transparencykey to an unused color, nothing changes
- added a bmp as the form's background image, still stays white
- checked my code to see if I was every writing directly to the form background
I can't fingure out how to fix this; does anyone have any ideas?
EDIT:
I found the answer to my question. SetStyle(ControlStyles.Opaque, true) was called in my constructor. I'm not sure what exactly that does, but I commented it out and it fixed my problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请列出要求意味着您到底需要什么?
我读完你的问题后。以下是我的理解。
如果您的问题是更改窗口大小,则
使用拆分容器,即
工具箱中可用
“容器”组。
设置其Dock属性来填充
填充整个窗口如果
调整大小/最大化。
然后使用右窗格包含图片框,左窗格包含其他控件。
如果需要,您还可以设置图片框的停靠属性以填充其父容器即右窗格。
如果您的问题是窗口的背景颜色,那么
实际上,如果表单是 Mdi 容器,则会出现背景颜色问题。
检查 IsMdiContainer 属性是否设置为 false。如果为 true,则为 MdiContainer。
以下代码块将 Mdi Forms 的背景色设置为表单的背景色。
Please list out the requirements means exactly what you need?
After I read your question. The following are my understandings.
If your problem is with changing window size, then
make use of Split container, which is
available in toolbox from
'Containers' group.
set its Dock property to fill to
fill entire window if
resized/maximized.
Then use the right pane to contain your picture box and left pane for other controls.
If you require, you may also set dock property of picture box to fill to its parent container means right pane.
If your problem is with background color of the window, then
Actually Background color issue comes, If the form is an Mdi Container.
Check whether IsMdiContainer property is set to false. If true it is an MdiContainer.
The following code block sets Mdi Forms' backcolor to the forms' backcolor.
我找到了我的问题的答案。 SetStyle(ControlStyles.Opaque, true) 在我的初始化中被调用。我不确定这到底是什么,但这是我的背景颜色问题的原因。
I found the answer to my question. SetStyle(ControlStyles.Opaque, true) was called in my initialization. I'm not sure what exactly that does, but it was the cause of my background color issue.