社区
C#
帖子详情
C# 如何获取控件的hdc呢?
kudiao119
2013-03-08 12:29:17
C# 怎么获取控件的hdc?
只能通过API来获取么?
不是获取hwnd
...全文
3118
1
打赏
收藏
C# 如何获取控件的hdc呢?
C# 怎么获取控件的hdc? 只能通过API来获取么? 不是获取hwnd
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
1 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
billlyh
2013-03-08
打赏
举报
回复
我也想知道答案,先帮你顶起来吧
C#
WinForm
控件
美化扩展系列之ListView
前面的一篇文章
C#
WinForm
控件
美化扩展系列之ListView(2)中,存在列表项文本错乱的问题,这是因为绘制文本的时候不小心选错了一个属性,把SubItem选成了Item,所以总会得到了第一项的文本。除了修正这个错误外,对列表项选中后的背景画法进行了改变,使得选中的列表项不在是每个子项都有一个矩形边框,而是全部只有一个矩形边框。另外,实现了对ListView的边框的重绘,可以轻易的更换边框颜色。 如下: private void WmNcPaint(ref Message m) { base.WndProc(ref m); if (base.BorderStyle == BorderStyle.None) { return; } IntPtr
hDC
= NativeMethods.GetWindowDC(m.HWnd); if (
hDC
== IntPtr.Zero) { throw new Win32Exception(); } try { Color backColor = BackColor; Color borderColor = _borderColor; Rectangle bounds = new Rectangle(0, 0, Width, Height); using (Graphics g = Graphics.From
Hdc
(
hDC
)) { using (Region region = new Region(bounds)) { region.Exclude(AbsoluteClientRectangle); using (Brush brush = new SolidBrush(backColor)) { g.FillRegion(brush, region); } } ControlPaint.DrawBorder( g, bounds, borderColor, ButtonBorderStyle.Solid); } } finally { NativeMethods.ReleaseDC(m.HWnd,
hDC
); } m.Result = IntPtr.Zero; }
C#
WinForm
控件
美化之ImageComboBox
这篇文章中我们重点需要实现的是(3)、(4)两项功能,下面我们来介绍具体实现的方法。 第一步,实现ImageComboBoxItem类。 要实现显示图标,当然要给每个项添加与图标相关的信息了,ImageComboBoxItem类应该包括以下内容:文本(Text)、缩进的级别(Level)、图标的索引(ImageIndex、ImageKey),用户数据(Tag)。ImageComboBoxItem类实现了ISerializable接口,实现自定义序列化。ImageComboBoxItem类的类视图如下: 图3 ImageComboxItem类视图 ImageComboBoxItem类的代码如下: [Serializable] [DefaultProperty("Text")] [TypeConverter( typeof(ExpandableObjectConverter))] public class ImageComboBoxItem : IDisposable, ISerializable ...{ Fields#region Fields private ImageComboBox _imageComboBox; private string _text = "ImageComboBoxItem"; private ImageComboBoxItemImageIndexer _imageIndexer; private object _tag; private int _level; #endregion Constructors#region Constructors public ImageComboBoxItem() ...{ } public ImageComboBoxItem(string text) : this(text, -1, 0) ...{ } public ImageComboBoxItem( string text, int imageIndex) : this(text, imageIndex, 0) ...{ } public ImageComboBoxItem( string text, string imageKey) : this(text, imageKey, 0) ...{ } public ImageComboBoxItem( string text, int imageIndex, int level) : this() ...{ _text = text; ImageIndexer.Index = imageIndex; _level = level; } public ImageComboBoxItem( string text, string imageKey, int level) : this() ...{ _text = text; ImageIndexer.Key = imageKey; _level = level; } protected ImageComboBoxItem( SerializationInfo info, StreamingContext context) : this() ...{ Deserialize(info, context); } #endregion Properties#region Properties [Localizable(true)]
C#
Winform
控件
应用
本课程详细介绍Winform各种
控件
的属性、方法、事件和使用技巧
获取
HDC
的几种方法
当需要在显示器上(当然包括打印机等设备上)绘图时,或者写文字的时候,需要取得设备的上下文句柄,即
HDC
,本文以下都称为
HDC
。那么,有哪些办法取得
HDC
呢? 1 BeginPain()和EndPaint() 在处理WM_PAINT消息时,使用
hdc
= BeginPaint(hwnd, &ps); //... EndPaint(hwnd, &ps); ps是类型为P...
c#
获取
控件
指定坐标的像素值
[DllImport("gdi32.dll")] private static extern uint GetPixel(IntPtr
hDC
, int XPos, int YPos); Graphics g = control.CreateGraphics(); uint colorref = GetPixel(g.Get
Hdc
(), center.X + convolution[i, j].X, center.Y + convolution.
C#
110,534
社区成员
642,576
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章