473,387 Members | 1,420 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

I created new userControl empty & used paint event and drawstring but have bugs help:

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace WindowsFormsApplication1
  11. {
  12.     public partial class NewsControl : UserControl
  13.     {
  14.         public NewsControl()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.  
  19.         private void NewsControl_Paint(object sender, PaintEventArgs e)
  20.         {
  21.             // Create string to draw.
  22.             String drawString = "Sample Text";
  23.             // Create font and brush.
  24.             Font drawFont = new Font("Arial", 16);
  25.             SolidBrush drawBrush = new SolidBrush(Color.Black);
  26.             // Create point for upper-left corner of drawing.
  27.             float x = 150.0F;
  28.             float y = 50.0F;
  29.             // Set format of string.
  30.             StringFormat drawFormat = new StringFormat();
  31.             drawFormat.FormatFlags = StringFormatFlags.DirectionVertical;
  32.             // Draw string to screen.
  33.             e.Graphics.DrawString(drawString, drawFont, drawBrush, x, y, drawFormat);
  34.         }
  35.     }
  36. }
  37.  
I drag the control from the toolbox to form1 and i see in it Sample Text and when i run my program nothing is shown up in the control.

I tried in the control code to put in the end : this.Refresh(); and this.Validate();

But then when im doing rebuild project my program got stuck and the control in the form1 designer is blinking before i even run the application.

Whats wrong here?



Thanks.
Jan 12 '11 #1
0 968

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Rene | last post by:
Currently, the paint even will only acknowledge painting going on inside of the ClipRectangle, any of the drawing that is outside of the ClipRectangle is ignored. How can I get the paint...
7
by: Schorschi | last post by:
I know there is a way to do this, but I don't know how. Via a custom event? I have some code that I only want to run during a paint event. I could build a form instance that has the code and...
5
by: active | last post by:
This is what I do in a PictureBox New: b1 = New Drawing.Bitmap(Width, Height, Me.CreateGraphics()) g1 = Graphics.FromImage(b1) Someplace I do g1.DrawString.........
2
by: Matthew | last post by:
I have a main form that creates several other forms. I would like to use one of those created forms to trigger the paint event for all the other created forms. Is this possible? Matthew
4
by: Aaron Smith | last post by:
I have a panel that I have in the paint event to draw a Raised 3d border around it.. The problem is, if a msgbox is popped up or a tooltip is displayed, it leaves lines on the panel. I've tried...
7
by: Dennis | last post by:
I am trying to implement drawing on a bitmap and using bitblt to transfer it to the control graphics object in the paint event. It seems to draw on the bitmap ok but doesn't get transferred to the...
7
by: hamil | last post by:
The following code will display a tif file on a form. When another form is moved over the tif image, the tif image is erased where the form was moved. A paint event occurs when this happens. My...
4
by: Sam | last post by:
Hai, I use a paintbox paint event to draw some images in a paintbox. I call the paint event by refreshing the paintbox using paintboxname.refresh() or paintboxname.update(). Problem with this...
4
by: Kürşat | last post by:
Hi all, I do some drawing in a form's paint event handler and I have a button on that form. Whenever the mouse enters or leaves the button Form's paint event occurs. Isn't that a strange...
7
by: Rotsey | last post by:
Hi, I have a interface that I use for a form so I can pass the form to another object. How do I add the Paint event to the interface and subsequently handle the paint event in my other...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.