|
Hi All,
I'm trying to chenge the color of my ProgressBar without building a new component from scratch.
I tried inheriting from System.Windows.Forms.ProgressBar and use the code below (which I found in several forums), but it's not working (if relevant, I'm working on vista 64).
Any ideas?
class MyProgressBar : ProgressBar
{
[DllImport("User32.Dll")]
public static extern int SendMessage(int hwnd, int wMsg, int wParam, int lParam);
public const int PBM_SETBKCOLOR = 0x2001;
public const int PBM_SETBARCOLOR = 0x409;
public void SetProgressBackColor(Color c)
{ int a = Convert.ToInt32(c.R.ToString());
int b = Convert.ToInt32(c.G.ToString());
int d = Convert.ToInt32(c.B.ToString());
int tot = Convert.ToInt32(ColorTranslator.ToOle(Color.FromArgb(a, b, d)).ToString());
int j = this.Handle.ToInt32();
SendMessage(j, PBM_SETBKCOLOR, 0, tot);
}
public void SetProgressForeColor(Color c)
{ int a = Convert.ToInt32(c.R.ToString());
int b = Convert.ToInt32(c.G.ToString());
int d = Convert.ToInt32(c.B.ToString());
int tot = Convert.ToInt32(ColorTranslator.ToOle(Color.FromArgb(a, b, d)).ToString());
int j = this.Handle.ToInt32();
SendMessage(j, PBM_SETBARCOLOR, 0, tot);
}
}
Thanks!
|
|
|
|
|
eyalbi007 wrote: int a = Convert.ToInt32(c.R.ToString());
Seriously, why would you do that? Its effect is equivalent to that of int a = c.R; , but a lot slower.
Oh and your SendMessage signature is incorrect.
Use:
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
static extern IntPtr SendMessage(IntPtr hWnd, Int32 Msg, IntPtr wParam, IntPtr lParam);
|
|
|
|
|
I think this would be the best option...
int a = (int)Double.Parse(Convert.ToInt32(c.R.ToString())).ToString();
... Actually that mind need a little work still (wheres the 'ive wet myself with laughter' smiley???)
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Give me a break, it's just a code I copied fom the web...
|
|
|
|
|
Well, change it..
It needs to be changed anyhow, because of the required IntPtr's. They are actually required here because you trying to run it in 64 bit mode which is expecting 64 bit arguments and you're passing 32 bit ones.
I wouldn't trust such badly written code at all
|
|
|
|
|
Well, still not working...
|
|
|
|
|
Well, show us the codez.. and tell us what it's doing (if anything)
|
|
|
|
|
Here's the code (that indeed does nothing).
What I was hopint it'll do is paint the prorgesss bar in different color than green (the Windows default color), by pressing button2. button1 simply advances the bar.
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
public const Int32 PBM_SETBKCOLOR = 0x2001;
public const Int32 PBM_SETBARCOLOR = 0x0409;
public void SetProgressBackColor(Color c)
{ int a = c.R;
int b = c.G;
int d = c.B;
int tot = ColorTranslator.ToOle(Color.FromArgb(a, b, d));
IntPtr j = this.progressBar1.Handle;
SendMessage(j, PBM_SETBKCOLOR, 0, tot);
}
public void SetProgressForeColor(Color c)
{ int a = c.R;
int b = c.G;
int d = c.B;
int tot = ColorTranslator.ToOle(Color.FromArgb(a, b, d));
IntPtr j = this.progressBar1.Handle;
SendMessage(j, PBM_SETBKCOLOR, 0, tot);
}
private void button1_Click(object sender, EventArgs e)
{
this.progressBar1.Minimum = 1;
this.progressBar1.Maximum = 10000;
this.progressBar1.Step = 1;
this.progressBar1.Value = 1;
for (int i = progressBar1.Minimum; i <= progressBar1.Maximum; i++)
{
progressBar1.PerformStep();
}
}
private void button2_Click(object sender, EventArgs e)
{
SetProgressBackColor(System.Drawing.Color.BlueViolet);
SetProgressForeColor(System.Drawing.Color.Red);
}
|
|
|
|
|
Well for one thing, the SendMessage signature still isn't correct. You absolutely have to use those annoying IntPtr's otherwise it won't work.
But then there's something else, I once heard (not sure how true it is) that progress bars in Vista may only be green yellow or red and that they have a special (different) message to change it. May be worth investigating.
|
|
|
|
|
Just make your own control, you can prob do in less code then you using to change it lol
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
eyalbi007 wrote: int j = this.Handle.ToInt32();
wrong
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Hello,
I am working on window application and i want to assign multicolor to text through programming,
I am filling data in Rich Text box and i want to assign different color to text like. word "Hello" in red word "Welcome" in blue etc.
I am working on C# kindly tell me what should i do and how this problem can be solve easily.
Thanks
|
|
|
|
|
Create one string array and in that array set all words,and give color to each item of array and finally convert all array items in single line string.
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
U need to use the selectedText and selectionColor properties of the Richtextbox.
Thanks & Regards,
Pramod
"Everyone is a genius at least once a year"
|
|
|
|
|
Hi
I have some problem while getting common data from two tables.
I have one dataset which contains tow datatables, one datatable contains 100 rows and second datatable contains 10 rows, both having one common field (example: currentdate), now i want matching rows from both table in one single table. how can i do it. please give me some example also.
Thank you
|
|
|
|
|
create a relation between the two tables?
|
|
|
|
|
hi...
i have used datarelation but i am not sure how to get that common data into one single table...can you give me some code for that.
Thank You.
|
|
|
|
|
I guess the straight forward way would be to loop through one table and for each row copy its data and all the related rows into the new table.
|
|
|
|
|
I get http://www.postimage.org/image.php?v=Pq1N1qmr[^] <- this error on one of the computers.
Dont know why.
this is the code:
try
{
label12.ForeColor = Color.Black;
string dbConnComm = "INSERT INTO Vnosi ([Dostava],[Skatla],[Barkoda],[Oznaka],[Skener],[Operater],[Datum],[PosnetkiV3],[PosnetkiM3],[Opombe]) VALUES ("
+ cmbDostava.Text + ", "
+ cmbSkatla.Text + ", '"
+ cmbBarkoda.Text + "', '"
+ cmbEnota.Text + "', '"
+ cmbSkener.Text + "', '"
+ cmbOperater.Text + "', '"
+ cmbDatum.Text + "', "
+ txtVA3.Text + ", "
+ txtMA3.Text + ", '"
+ txtOpombe.Text + "')";
SqlConnection dbConn = new SqlConnection(sqlConnection);
dbConn.Open();
SqlCommand dbComm = new SqlCommand(dbConnComm, dbConn);
dbComm.ExecuteNonQuery();
dbConn.Close();
label12.Text = "Uspešno vnešeno";
}
catch(Exception ex)
{
label12.ForeColor = Color.Red;
label12.Text = "Napaka pri vnosu";
MessageBox.Show("Napaka: " + ex.ToString());
}
PC has framework 2.0 and 1.1
|
|
|
|
|
A few quick question to help try find the answer.
Have you tried the insert into the database directly and dose it work?
What is the connection string you are using as it appears to be a connection issue?
Can you connect to the database from that machine?
Why are you using an insert? you should look at using a stored procedure as direct sql asks for an injection attack.
|
|
|
|
|
|
Yes Giorgi, thank you for your information on security about SQL injections.
I just needed an anwser which was more than funny. The SQL Connection string was wrong.
And its my bad that i forgot to mention that this error occurs only on computers which have low-access accounts in our domain. Now i've fixed this and it works.
HopingToCode was right. I should check the connection string. Which i did today.
Thank you both for your time.
Regards,
Matjaž
|
|
|
|
|
I am not able to attach Application.Idle event with the event handler. what will be the reasons??
thanks
|
|
|
|
|
saksp wrote: what will be the reasons
Maybe you're doing it wrong?
This works for me.
using System;
using System.Windows.Forms;
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Application.Idle += new EventHandler(Application_Idle);
}
void Application_Idle(object sender, EventArgs e)
{
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
saksp wrote: I am not able to attach Application.Idle event with the event handler. what will be the reasons??
You're doing it wrong.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|