WinForms (.NET) 按钮最大化时锚定
好吧,我已经用谷歌搜索了,但也许我的搜索方式很奇怪。 :/
我有一个 VB.NET WinForms 应用程序。 我为所有控件设置了锚点属性,以便在表单最大化时调整所有控件的大小,使其看起来合适。 (但是还没有开始手动调整大小)。
无论如何,问题是:
我在主 GUI 表单/图片上为按钮设置相同的属性(现在使用单个按钮进行测试)。 当我通过 F5 运行该程序时,它看起来不错。 但是当我最大化表单时,整个按钮覆盖的内容超出了应有的范围。
我已经截取了表单的屏幕截图,以便您可以看到我正在谈论的内容的视觉效果。 :/
之前:http://zack.scudstorm.com/before.png
之后: http://zack.scudstorm.com/after.png
还有什么属性(y |ies) 我需要设置按钮才能正确显示吗? :/(这些按钮会覆盖显示“1-1”、“2-3”等的框。
谢谢,
-扎克
Ok, I have googled, but maybe I put my search in weirdly. :/
I have a VB.NET WinForms application. I have the anchor properties set for all the controls so that it will resize all the controls to look decent when the form is maximized. (Haven't gotten around to manual resizing yet however).
Anyway, the problem:
I go to set the same properties for a button (testing with a single button for now) on the main GUI form/picture. When I go to run the program via F5, it looks decent. But when I maximize the form, the entire button covers up more than it should.
I've taken screenshots of the form so you can see a visual of what I'm talking about. :/
Before: http://zack.scudstorm.com/before.png
After: http://zack.scudstorm.com/after.png
What other propert(y|ies) do I need to set for the buttons to show up correctly? :/ (The buttons go over the boxes that say, for example, "1-1", "2-3", etc.
Thanks,
-Zack
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您想要的只是左上角时,似乎您已经锚定了左上角和右下角。
编辑:如果它只是一个在 winform 更改时不会更改的图像,那么根本不要锚定按钮。 只需将它们放在它们该去的地方即可。 如果您要缩放图像,那么我要么检测图像上的点击并进行缩放数学,要么进行缩放数学并在 Form.OnResize 事件中的代码中设置按钮。
Seems like you have anchored top-left and bottom-right when what you want is just top-left.
Edit: If it's just an image that does not change when the winform changes, then don't anchor your buttons at all. Just put them where they go. If you are scaling the image, then I would either detect the clicks on the image and do the scaling math or do the scaling math and set my buttons in code in the Form.OnResize event.
看来您的目标只是能够处理“计算机”上的点击...
对于此类任务有用的一个选项是创建一个“覆盖”位图(未显示,但它是准确的)与源位图大小相同),它使用不同的颜色来表示所有可单击区域。 (例如,
(R=0,G=0,B=0)
表示计算机 0,(0,0,1)
表示计算机 1,等等)您甚至可以生成该位图有点自动,没有太多麻烦(如果您有一种模式,您可以单击图像的左上角,然后单击右下角来定义新区域)
单击鼠标时,您可以检查缩放坐标处的像素覆盖层中的鼠标位置并确定其点击对应的内容。 这比创建大量控件要容易得多,并且可以更容易地创建非矩形的可点击区域。
As it appears that your goal is just to be able to handle clicks on the "computers"...
One option that can be useful for this sort of task is to create an "overlay" bitmap (not displayed, but which is the exact same size as your source bitmap) which uses different colors to represent all the clickable regions. (e.g.
(R=0,G=0,B=0)
for computer 0,(0,0,1)
for computer 1, etc)You could even generate this bitmap somewhat automatically without too much trouble (If you have a mode where you can click the top left and then bottom right corners of the image to define a new region)
When the mouse is clicked, you can check the pixel at the scaled coordinates of the mouse position in the overlay and determine what their click corresponds to. This can be a lot easier than creating loads of controls, and makes it a lot easier to have clickable regions that aren't rectangular.