onpaint

Populating a FlowLayoutPanel with a large number of controls and painting thumbnails on demand

随声附和 提交于 2019-12-04 22:24:45
问题 I'm trying to make an ImageListBox kind of control that will display a large numbers of thumbnails, like the one that Picasa uses. This is my design: I have a FlowLayoutPanel that is populated with a lot of UserControl objects, for example 4,000. Each UserControl is assigned a delegate for the Paint event. When the Paint event is called, it checks a memory cache for the thumbnail and if the image is not in cache, it retrieves it from the disk. I have two problems that I'm trying to solve: It

Create custom ComboBox with rounded corners in Windows Forms

最后都变了- 提交于 2019-12-04 18:17:25
I want to create a custom combo-box with rounded corners and gradient color. I have implemented the same feature in Button by overriding the OnPaint method. But it is not working for ComboBox . Any help will be appreciated. The code I am using for overriding OnPaint is given below: protected override void OnPaint(PaintEventArgs paintEvent) { Graphics graphics = paintEvent.Graphics; SolidBrush backgroundBrush = new SolidBrush(this.BackColor); graphics.FillRectangle(backgroundBrush, ClientRectangle); graphics.SmoothingMode = SmoothingMode.AntiAlias; Rectangle rectangle = new Rectangle

Exceptions and Access Violations in Paint events in Windows

余生颓废 提交于 2019-12-04 09:12:24
After executing some new code, my C++ application started to behave strange (incorrect or incomplete screen updates, sometimes no screen updates at all). After a while we found out that the new code is causing an Access Violation. Strange enough, the application simply keeps on running (but with the incorrect screen updates). At first we thought the problem was caused by a "try-catch(...)" construction (put there by an overactive ex-colleague), but several hours later (carefully inspecting the call stacks, adding many breakpoints, ...) we found out that if there's an Access Violation in a

What is the proper way to draw a line with mouse in C#

半世苍凉 提交于 2019-12-04 00:55:48
问题 This is my drawing code to draw a custom line with mouse onto a Chart. Can you please help me to do it proper way ? namespace Grafi { public partial class Form1 : Form { bool isDrawing = false; Point prevPoint; public Form1() { InitializeComponent(); } private void chartTemperature_MouseDown(object sender, MouseEventArgs e) { isDrawing = true; prevPoint = e.Location; } private void chartTemperature_MouseMove(object sender, MouseEventArgs e) { Pen p = new Pen(Color.Red, 2); if (isDrawing) {

Graphics DrawString to Exactly Place Text on a System.Label

 ̄綄美尐妖づ 提交于 2019-12-03 16:55:26
I have overridden the OnPaint method of my Label control in VS2008: void Label_OnPaint(object sender, PaintEventArgs e) { base.OnPaint(e); dim lbl = sender as Label; if (lbl != null) { string Text = lbl.Text; e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; if (myShowShadow) { // draw the shadow first! e.Graphics.DrawString(Text, lbl.Font, new SolidBrush(myShadowColor), myShadowOffset, StringFormat.GenericDefault); } e.Graphics.DrawString(Text, lbl.Font, new SolidBrush(lbl.ForeColor), 0, 0, StringFormat.GenericDefault); } } This works, but I really want to find out

How to make a control to be painted/refreshed properly

坚强是说给别人听的谎言 提交于 2019-12-02 21:52:26
问题 I have a control derived from checkbook which I called "SettingBooleanButton", but when any window or dialog is dragged over the control the control keeps signs of the drag The next image shows the effect of dragging an application window over control This is the code block that I have for OnPaint() Public Class SettingBooleanButton Inherits CheckBox Private _settingSection As String Private _settingName As String Private _associatedSetting As Setting Public Event StateChange(ByVal

A problem with overriding OnPaint when DoubleBuffered set to true

荒凉一梦 提交于 2019-12-02 13:51:20
问题 I have created a custom control which derives from Panel. I use it to display an Image using BackgroundImage property. I override the OnClick method and set isSelected to true then call Invalidate method and draw a rectangle in overrided OnPaint. Everything goes just fine until I set DoubleBuffered to true. The rectangle is drawn and then it is erased and I can't get why this is happening. public CustomControl() : base() { base.DoubleBuffered = true; base.SetStyle(ControlStyles

How to make a control to be painted/refreshed properly

眉间皱痕 提交于 2019-12-02 10:11:20
I have a control derived from checkbook which I called "SettingBooleanButton", but when any window or dialog is dragged over the control the control keeps signs of the drag The next image shows the effect of dragging an application window over control This is the code block that I have for OnPaint() Public Class SettingBooleanButton Inherits CheckBox Private _settingSection As String Private _settingName As String Private _associatedSetting As Setting Public Event StateChange(ByVal affectedSetting As Setting) Sub New() ' This call is required by the designer. InitializeComponent() ' Add any

C# WinForms - Paint method questions

北城以北 提交于 2019-12-01 18:02:12
问题 I am not sure what is the best way of using graphics - should I attach my classes to main form Paint event and then do the drawing, or it is better to call it from overidden OnPaint void like this? I mean, is it OK to do that like this: protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e) //what is this good for? My app works without it as well Graphics g=e.Graphics; DrawEnemies(g); UpdateHUD(g); DrawSelectedUnit(g); } 回答1: It is recommended that controls override the On...

Drawing an image onto a Panel control gives artefacts when resizing

陌路散爱 提交于 2019-12-01 16:38:56
Currently I'm trying to do what I thought would be a simple task: Draw an image onto the full area of a Panel control in Windows Forms. (Please ignore for the moment that I could use the BackgroundImage property ) The image to draw looks like this: I.e. a yellow box with an 1 pixel blue frame around. To draw, I'm using the Paint event of the Panel control: private void panel1_Paint(object sender, PaintEventArgs e) { e.Graphics.DrawImage(Resources.MyImage, panel1.ClientRectangle); } This looks fine when initially displaying the form: When resizing the form (and the docked panel, too), it either