|
Hello everybody
I have a Form and I use the GDI+ to have a User Interface
I have a Button(just an image) that should be repainted when it is clicked
and I use a flag at the mouse event handler to know when the button is clicked
and in the OnPaint method I check it FIRST, and if the flag was True I don't paint
the BackGroundImage, because it is painted before (at the startup of the Form)
but I don't know why that BackGroundImage is gone when the event occures
and only my button and the BackColor of the Form is shown
=>>note: I don't want to use BackGroundImage because I think it will paint it all the times that the Form is repainted, and it is process intensive
Thank you
P.S: If you want to read this code better you can copy/paste it in VS.NET and
select all the code and use CTRL + (K) then CTRL + (F) to format the code
in a good format to be more readable
here is the OnPaint method:
<br />
protected override void OnPaint(PaintEventArgs e)<br />
{<br />
if (LanguageTraining)<br />
{<br />
dc.DrawImage(ButtonSelectedBlue, LanguageButtonBounds);<br />
LanguageTraining = false;<br />
base.OnPaint(e);<br />
return;<br />
}<br />
base.OnPaint(e);<br />
Graphics dc = e.Graphics;<br />
dc.TranslateTransform(AutoScrollPosition.X, AutoScrollPosition.Y);<br />
<br />
<br />
dc.TranslateTransform(AutoScrollPosition.X, AutoScrollPosition.Y);<br />
dc.DrawImage(piccy, piccyBounds);<br />
dc.DrawString("Language Training", ButtonFont, TextBrush, new Point(755, 625));<br />
<br />
<br />
}<br />
Here is all the code
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Linq;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
<br />
namespace paintImage<br />
{<br />
public partial class Form1 : Form<br />
{<br />
private bool LanguageTraining = false;<br />
private Point MouseClickPosition;<br />
private readonly Brush TextBrush = Brushes.White;<br />
private readonly Font ButtonFont = new Font("alefba", 18,FontStyle.Bold);<br />
<br />
readonly Image piccy;<br />
readonly Image ButtonSelectedBlue;<br />
readonly Image ButtonSelectedGreen;<br />
private readonly Point[] piccyBounds;<br />
private readonly Point[] LanguageButtonBounds;<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
piccy = Image.FromFile(@"C:\pics\page1.png");<br />
<br />
ButtonSelectedBlue = Image.FromFile(@"C:\pics\Button Selected Blue.png");<br />
ButtonSelectedGreen = Image.FromFile(@"C:\pics\Button Selected Green.png");<br />
AutoScrollMinSize = piccy.Size;<br />
piccyBounds = new Point[3];<br />
LanguageButtonBounds = new Point[3];<br />
<br />
const int resolutionX = 1024;
const int resolutionY = 768;
<br />
<br />
piccyBounds[0] = new Point(0, 0);<br />
piccyBounds[1] = new Point(resolutionX, 0);<br />
piccyBounds[2] = new Point(0, resolutionY);<br />
<br />
LanguageButtonBounds[0] = new Point(744, 617);<br />
LanguageButtonBounds[1] = new Point(992, 617);<br />
LanguageButtonBounds[2] = new Point(744, 659);<br />
<br />
}<br />
<br />
protected override void OnPaint(PaintEventArgs e)<br />
{<br />
if (LanguageTraining)<br />
{<br />
dc.DrawImage(ButtonSelectedBlue, LanguageButtonBounds);<br />
LanguageTraining = false;<br />
base.OnPaint(e);<br />
return;<br />
}<br />
base.OnPaint(e);<br />
Graphics dc = e.Graphics;<br />
dc.TranslateTransform(AutoScrollPosition.X, AutoScrollPosition.Y);<br />
<br />
<br />
dc.TranslateTransform(AutoScrollPosition.X, AutoScrollPosition.Y);<br />
dc.DrawImage(piccy, piccyBounds);<br />
dc.DrawString("Language Training", ButtonFont, TextBrush, new Point(755, 625));<br />
<br />
<br />
}<br />
protected override void OnKeyUp(KeyEventArgs e)<br />
{<br />
base.OnKeyUp(e);<br />
if (e.KeyCode == Keys.Escape)<br />
this.Close();<br />
}<br />
protected override void OnMouseDown(MouseEventArgs e)<br />
{<br />
base.OnMouseDown(e);<br />
MouseClickPosition = new Point(e.X, e.Y); <br />
}<br />
protected override void OnMouseClick(MouseEventArgs e)<br />
{<br />
base.OnMouseClick(e);<br />
if (MouseClickPosition.X > 755 && MouseClickPosition.X < 1024 && MouseClickPosition.Y > 625 && MouseClickPosition.Y < 768)<br />
{<br />
Invalidate();<br />
LanguageTraining = true;
}<br />
}<br />
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
<br />
}<br />
}<br />
}<br />
<br />
<br />
modified on Saturday, June 20, 2009 7:56 AM
|
|
|
|
|
Hi,
1.
you can show formatted code by using PRE tags instead of CODE tags
2.
There must be several ways to prevent a background repaint.
for one I would try without the base.OnPaint() statement;
alternatively you can have a look at the ControlStyles Enumeration, and the Control.SetStyle method.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Hi,
and thank you for your answer but unfortunately I eliminated the "e.base();"
from the code but the problem wasn't solved
I am trying the other option you mentioned
modified on Saturday, June 20, 2009 8:29 AM
|
|
|
|
|
hi,
i have a Ip address and i want to change it into Variant VT_I4 and then change type to VT_BSTR in .net. Let me know how to do it
|
|
|
|
|
There is no variant in .NET. You could try to use an object instead. I googled for you and couldn't find any better advice.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Hi,
I am developing an application in which i use to select data from one grid remove that & display it to the second grid.
I store those data in a local mdb file . when i am selecting rows in bulk(around 50-70 at a time)and then wanted to cut and display in the second grid i am getting this error .
Please help.
|
|
|
|
|
The error means what it says. Your code is locking the MDB. Not sure what sort of help you're hoping for, when you don't post any code.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
hi there,
I have a simple WPF window with a button in it.
now during runtime, i pass this button control to another function, and there, i want to know the parent of this control. ie the window, with the full namespace.
any way for this thru C#
The name is Sandeep
|
|
|
|
|
We have a WPF forum. The control has a parent property, to know the type, you can use the GetType method, you can also use reflection. Any method that gets passed a control, sounds a little ugly to me.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
hi,
thnx for the reply..
The name is Sandeep
|
|
|
|
|
Hi
Because of various graphics that i use in my app, I want my app to run under Windows Classic Theme regardless of the theme the user has selected before they run my app.
Where can I find info about the API calls I need to swtich tmeme at start up and to restore to users' chosen theme on exit?
Thanks.
|
|
|
|
|
Swapping the whole system theme is a little user hostile. It would be better to skin your app to make it look the way you want.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
That's basically what I want to do, but using Windows Classic Theme for the skin instead of a custom skin, but didn't think of it that way.
Now all I have to do is find out how to do it - there are a lot of articles about skinning, so it is difficult to find the best article to look at.
|
|
|
|
|
Hi All
I'm working on a little web browser that supports tabs and all is good but everytime I click a link that is supposed to open in a new tab or window, instead of opening a new window/tab in my own web browser that i am making, it chooses to open a new instance of the system's default web browser (Internet Explorer) and I have tried to find some articles/samples on the web but have been unsuccessful.
Does anybody know how I would go about allowing links to be opened in a new tab in the browser i am making?
Any suggestions would be greatly appreciated
thanks
jason
|
|
|
|
|
Well, unless I misse the memo ( possible ), the web browser control doesn't support tabs. So, you'd have to catch the event of a page opening, swallow it, and create your own tab, and open the URL there.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
thanks christian, that's exactly what i'm trying to figure out, i obviously didn't explain my situation properly in my first message, sorry. I'll keep looking
|
|
|
|
|
http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser_members.aspx[^]
Reading the MSDN, it looks like the NewWindow[^] event is what you want.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Thank you Christian for yout time and help, that link was very useful. I'm actually wondering how I could've overlooked that page in the first place.
Well, I am now browsing the web with full tab support yay! Thanks again christian. Maybe I could turn this into an article??
|
|
|
|
|
Well, if you finish the project, then I'd imagine you could write an article which covers this and other things you learned along the way. People are always writing their own browsers, so I'm sure it would be well recieved.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
I'm planning on adding a new type of favorites system, but also supporting existing favorites that have been created by other browsers, once that's finished I'll start writing the article. I'd love to see what others have to say about it.
|
|
|
|
|
hi,
zhe subject is that
class Class1 {
private string str = "class1.str";
private int i = 0;
static void StringConvert(string str) {
str = "string being converted.";
}
static void StringConvert(Class1 c) {
c.str = "string being converted.";
}
static void Add(int i) {
i++;
}
static void AddWithRef(ref int i) {
i++;
}
static void Main() {
int i1 = 10;
int i2 = 20;
string str = "str";
Class1 c = new Class1();
Add(i1);
AddWithRef(ref i2);
Add(c.i);
StringConvert(str);
StringConvert(c);
Console.WriteLine(i1);
Console.WriteLine(i2);
Console.WriteLine(c.i);
Console.WriteLine(str);
Console.WriteLine(c.str);
Console.Read();
}
tell me why "Console.WriteLine(str);" and "Console.WriteLine(c.str);"
zhe two sentence have two different results!
I know that zhe "string" is reference type!
but here i am puzzled!
modified on Saturday, June 20, 2009 8:09 AM
|
|
|
|
|
While you are correct that string is a reference type, you cannot change which string the local variable str in Main is referencing from the StringConvert function since you pass it by value. All you can do is make the parameter to StringConvert refer to another string, which will have no effect outside the function.
In the case where you passed a Class1, you are modifying the reference contained in the object referred to by the parameter, which is the same object referred to in Main. If you had put the line c = new Class1(); as the first line in StringConvert, it would no longer change the value in Main because the parameter in StringConvert would now be referring to a different object.
|
|
|
|
|
i want to send mail to yahoo mail automatically using c# code.
|
|
|
|
|
|
I want a Porche.....
Seriously, what have you tried ? Why do you have a specific issue with yahoo mail ? A quick google leads me to believe that a lot of people are asking this, so perhaps the issue is that yahoo does not support sending mail through a third party, or through the protocols that .NET supports.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|