表格单元格内停靠的图片框大小,c# [英] Size of docked picturebox inside a table cell, c#

查看:43
本文介绍了表格单元格内停靠的图片框大小,c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

帮助新手!我只是一个业余爱好的程序员,所以请耐心等待。



我有一张停靠的图片框,我正在努力缩放他们内部的照片达到图片盒的大小。因此,例如,如果我最大化窗口,照片也会调整大小。我知道picturebox具有自动缩放的属性,但我在这里做的其他事情会产生适得其反的效果。所以我需要找到一种编码方式。有趣的乐趣!



问题是我无法获得图片盒的大小。我想这可能是因为他们停靠在桌子上。所以,我需要找到另一种方法来访问它们的维度。



另外,为了让事情变得更加困难,我已将此功能放入另一个类文件。我传递给函数的是picturebox句柄。我知道这让我可以访问它的属性,但我怀疑我必须以某种方式访问​​父单元格的属性。然后,那些自动尺寸也是.. smh



谢谢,伙计们!

Help a newbie out! I''m just a hobby programmer, so bear with me.

I have a table of docked pictureboxes where I''m trying to scale the photos inside them relative to the size of the pictureboxes. So, for instance, if I maximize the window the photos will also resize. I know picturebox has properties for automatic scaling, but I''m doing other things here that would make that counterproductive. So I need to find a way to code it. Fun fun!

The problem is that I can''t get the size of the pictureboxes. I think this is probably because they''re docked to fill the table cell. So, I need to find another way to access their dimensions if one exists.

Also, to make things even harder on myself, I''ve placed this function in another class file. What I''ve passed to the function is the picturebox handle. I know this gives me access to it''s properties, but I have a suspicion that I''ll have to somehow access the parent cell''s properties. Then again, those auto-size, too.. smh

Thanks, guys!

推荐答案

请看到我对这个问题的评论:你省略了一些让你的情况看起来不确定的细节。



我有一般的建议,基于以下经验法则:如果你开始遇到 PictureBox 的问题,那就去掉它了。



这个是因为这个班并不是真的需要。您始终可以使用GDI自行渲染任何控件中的任何图像。类 PictureBox 的唯一目的是创建一种在应用程序中显示静态图像的高度简化的方法。这只是父控件和带缩放的图像之间的中间人,如果你尝试多做一点,它就没有任何用处。



同时,在控件上立即渲染图像非常容易。在 PictureBox 开始为您提供最小麻烦的情况下,它将变得非常容易。您可以使用表格控件(无论是什么, DataGridView 或任何东西)在单元格中渲染图像,或插入任何其他控件,从<$ c $派生的自定义控件c> System.Windows.Forms.Control 或Panel并在其上渲染图像。



我解释一下并解释做什么在我过去的答案中:

如何从旧图纸中清除面板 [ ^ ],

在C#中绘制一个矩形 [ ^ ],

APPE和图片框内的图片 [ ^ ]。



另见过去的答案:

mdi子窗体之间的绘制线 [ ^ ],

在面板上捕获图纸 [ ^ ],

什么样的俏皮方法是Paint? (DataGridViewImageCell.Paint(...)) [ ^ ]。



新年快乐!



-SA
Please see my comment to the question: you omitted some details which makes your situation look uncertain.

I have a general advice for you, based just on the following rule of thumb: if you are starting to have trouble with PictureBox, its the time to get rid of it.

This is because this class is not really needed. You can always render any image in any control by yourself, using GDI. The only purpose of the class PictureBox is to create a highly simplified way of showing a static image in your application. This is just a middleman between a parent control and the image with scaling, it does not do anything useful if you try to do a bit more.

At the same time, immediate rendering of image on the control is very easy. And it will be dramatically easier in the situations where the PictureBox start giving you even the minimal trouble. You can render the image in the cell using a table control (whatever it is, DataGridView or anything), or insert any other control, a custom control derived from System.Windows.Forms.Control or Panel and render the image on it.

I explain it all and explain what to do in my past answers:
How do I clear a panel from old drawing[^],
draw a rectangle in C#[^],
Append a picture within picturebox[^].

See also these past answers:
Drawing Lines between mdi child forms[^],
capture the drawing on a panel[^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[^].

Happy New Year!

—SA


这篇关于表格单元格内停靠的图片框大小,c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆