|
In C# fore color of datimepicker have default color black.
Now, I want to change fore color :Black->blue
Do i do?
Thanks
|
|
|
|
|
Unfortunately this is not possible. MS have hardcoded it to use either SystemColors.ControlText or Colors.Black (I'm not sure which).
The ForeColor property is hidden as any change to it is ignored.
You can 'roll your own' by deriving from DateTimePicker . In the constructor call
Style(ControlStyles.UserPaint, true); then override OnPaint and draw it yourself.
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)
|
|
|
|
|
I don't normally give 'full' code but I've had a play around to make sure the advice I gave earlier was correct, so I figured I may as well share.
This enables use of the BackColor as well as ForeColor. I've used the DropDownButton part of the ComboBox for ease. I haven't implemented any of the editing on the text part of the control that is available in the .Net supplied one as that isn't quite as trivial! I also haven't checked the Enabled state to alter the way it's drawn, and I haven't drawn any border around the control as I can't remember how to get the colors in use by the system.
So there's plenty left to do but it should give you a start.
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
namespace MyControls
{
public class MyDateTimePicker : DateTimePicker
{
public MyDateTimePicker()
: base()
{
this.SetStyle(ControlStyles.UserPaint, true);
}
[Browsable(true),
EditorBrowsable(EditorBrowsableState.Always),
DefaultValue(typeof(Color), "Window")]
public override Color BackColor
{
get { return base.BackColor; }
set { base.BackColor = value; }
}
[Browsable(true),
EditorBrowsable(EditorBrowsableState.Always),
DefaultValue(typeof(Color), "WindowText")]
public override Color ForeColor
{
get { return base.ForeColor; }
set { base.ForeColor = value; }
}
protected override void OnPaint(PaintEventArgs e)
{
StringFormat stringFormat = new StringFormat();
stringFormat.LineAlignment = StringAlignment.Center;
using (Brush brush = new SolidBrush(BackColor))
{
e.Graphics.FillRectangle(brush, 0, 0, ClientRectangle.Width, ClientRectangle.Height);
}
using (Brush brush = new SolidBrush(ForeColor))
{
e.Graphics.DrawString(Text, Font, brush, ClientRectangle, stringFormat);
}
Rectangle dropDownRectangle = new Rectangle(
ClientRectangle.Width - Height, 0, Height, Height);
if (ComboBoxRenderer.IsSupported)
ComboBoxRenderer.DrawDropDownButton(e.Graphics, dropDownRectangle, ComboBoxState.Normal);
else
ControlPaint.DrawComboButton(e.Graphics, dropDownRectangle, ButtonState.Normal);
}
}
}
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)
|
|
|
|
|
hello sir/mam
i have a problem plz solve me out this problem.
i am working on a window application in c# .i have a datagrid which contain a DataGridBoolColumn and datagridtextboxcolumn.i am using table name as stock which contains feild subject,bookname,rate,sellrate,quantity.lbltotal is the label which shows the the total of sellrate.now my problem is that i have to show only those total which are checked
means if any one unchecked the check box the sellrate must be deducted in the from the total.
and i have to insert all the rows of the datagrid in the table except those which are uncheked.plz help me . thanks in advance
try
{
SqlConnection cn=new SqlConnection(Class1.connect());
SqlDataAdapter cmd=new SqlDataAdapter("select subject , bookname,rate,sellrate ,quantity from stock where class ='"+txtclass.Text+"'",cn);
// DataSet dt=new DataSet();
DataTable dt=new DataTable("stock");
cmd.Fill(dt);
dataGrid1.DataSource=dt;
this.dataGrid1.TableStyles.Clear();
DataGridTableStyle tb=new DataGridTableStyle();
tb.MappingName="stock";
DataGridBoolColumn td=new DataGridBoolColumn();
td.MappingName="rate";
td.HeaderText="";
td.AllowNull=true;
td.Width=20;
tb.GridColumnStyles.Add(td);
DataGridTextBoxColumn txt=new DataGridTextBoxColumn();
txt.MappingName="Subject";
txt.HeaderText="Subjects";
txt.Width=160;txt.ReadOnly=true;
tb.GridColumnStyles.Add(txt);
txt=new DataGridTextBoxColumn();
txt.MappingName="bookname";
txt.HeaderText="Book Name";
txt.Width=200;
txt.ReadOnly=true;
tb.GridColumnStyles.Add(txt);
txt=new DataGridTextBoxColumn();
txt.MappingName="sellrate";
txt.HeaderText="Rate";
txt.Width=160;
txt.ReadOnly=true;
tb.GridColumnStyles.Add(txt);
dataGrid1.TableStyles.Add(tb);
// SqlConnection cn=new SqlConnection(Class1.connect());
SqlCommand cd=new SqlCommand("select sum(sellrate) from stock where class='"+txtclass.Text+"'",cn);
cn.Open();
SqlDataReader dr=cd.ExecuteReader();
if(dr.Read())
{
lbltotal.Text="Total = "+dr[0].ToString();
}
else
{
lbltotal.Text="Total = 0 0";
}
cn.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message,Class1.name());
lbltotal.Text="Total = 0 0";
}
|
|
|
|
|
well, you should you make a function 'UpdateTotal' and call it on that column value change event.
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
I do not really understand what your mean,
I suggest if you can like this:
td.TrueValueChanged += new EventHandler(td_TrueValueChanged);
|
|
|
|
|
Send receive files over bluetooth, discover bluetooth devices using franson bluetools on Pocket PC (Windows Mobile)
modified on Saturday, March 7, 2009 3:39 PM
|
|
|
|
|
There's samples etc on the vendor's site[^] and a reference manual[^]. All that from the first result in Google[^].
Please search in future before asking here - especially when it comes to 3rd party tools!
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)
|
|
|
|
|
Dear friends,
i have a multi dimentional matrix, for example x[][], i want to sort it by one coloumn, for example:
coloumn 1: ab , uh, wh, ko, to
coloumn 2: 12, 8, 11, 3 , 1
Soretd Matrix that i want is:
coloumn 1: ab, wh, uh, ko, to
coloumn 2: 12, 11, 8, 3, 1
can anybody help me?
|
|
|
|
|
|
Depends on what exactly a column is - do you have have an array of rows or an array of columns?
If you have an array of rows, sorting by the first column should be easy:
(warning: untested)
static void SortByColumn<T>(T[][] data, int column) where T : IComparable<T>
{
Array.Sort<T[]>(data, (T[] row0, T[] row1) =>
{
return row0[column].CompareTo(row1[column]);
});
}
Last modified: after originally posted -- angle bracket formatting failure..
|
|
|
|
|
Hey guys,
I need to click pictures using a webcam.... in c#.....
how to do it???
Any reference or link will help a lot...
Waiting for ur reply
Umang Jain
|
|
|
|
|
What? A webcam is an image/video capture device. A mouse is a pointing/clicking/scrolling device. I don't see how you're going to make these interchangeable.
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)
|
|
|
|
|
i want to capture images using a webcamera in c#... whenever the user wants i.e. by clicking a button alongside....
|
|
|
|
|
Here[^] is one. If you search here / google you'll find many others.
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)
|
|
|
|
|
|
Hi everybody.
Just spent some very frustrating houres fighting with Vista.
Wanted to know, what exception I get, when I write to a folder where I hav no rights. OK - just some lines and I'll see:
StreamWriter sw = null;
try
{
sw = new StreamWriter( @"C:\Windows\System32\MyService\test.txt", true, Encoding.GetEncoding( "windows-1252" ) );
sw.WriteLine( "sometext" );
}
catch (Exception e)
{
MessageBox.Show( e, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning );
}
finally
{
if (sw != null) sw.Close();
}
I took C:\Windows\System32\MyService\test.txt because I was to lazy to change the rights of some testpath and I know (knew?) I could not write there as 'normal user'.
The result: no exception and no file???
what the?
check the path - OK
try to write from cmd (copy con: C:\Windows\System32\MyService\test.txt) - Access is denied. 0 file(s) copied.
So I change the rights for Users on C:\Windows\System32\MyService to Full Access.
Rerun of prog gives the same results???
copy con: now works
After some headscratching and wondering I changed the filename in the program to test2.txt. Now it writes the file. Back to test.txt - no exception and no writing???
Took away Full Access (and write and modify and write) and tried test3.txt. As expected no and no. Back to Full Access - test3.txt no and no, test4.txt no problem.
I created a new folder under System32. Same results as before.
If I do the same with a path like C:\testpath, everything works as expected. Normaly I can write, if I take away some rights (deny write or something) I get my exception (UnauthorizedAccessException by the way)
So how does .NET or something first supress an exception and then somehow remember it later?
Please help
Norbert
PS. please forgive any errors in my english
|
|
|
|
|
Typical Vista crappyness.. did you check whether the file was wrongly and silently redirected to some obscure place?
|
|
|
|
|
I tried, but didn't find it. Any idea where to look? And to prevent it from happening?
|
|
|
|
|
"logical" locations would include My Documents, the application's data folder, and NUL (nowhere, just silently discarded)
It might be more reliable (at least exception-wise) to create and write the file in a temporary place and then move or copy it to System32 (File.Move or File.Copy )
Then again, this is Vista. All bets are off. It has a habit of ignoring bad things silently but complaining loudly about not-so-bad things..
|
|
|
|
|
Nope. Can't find anything. I think I have to check after the first write, that there is something there.
Stupid.
But thanks anyhow.
|
|
|
|
|
At the catch clause in order to show the error message use:
System.Diagnostics.Trace.Assert(false,"Error:" + err.ToString());
OR if running a debug version:
System.Diagnostics.Debug.Assert(false,"Error:" + err.ToString());
Do not attempt to show a message box window when running a service. Your exception line throws an exception.
When writing files especially in vista, you should use Environment.SpecialFolder and not a hard coded path:
string dirPath = Environment.GetFolderPath(
Environment.SpecialFolder.LocalApplicationData);
Natza Mitzi
|
|
|
|
|
Hi
I am able to make both the client and the server to communicate ..
The message from the server is displayed in a listbox control..
I have displayed an acknowledgement message from the server say,"Welcome to the server "in the listbox.
I have also added a label box in a table control
If the received message is "welcome to the server" the color of the label should change...The following code does not give me any error but the color of the label is not changed.Can you spot out the mistake
data = new byte[1024];
int recv = sock.ReceiveFrom(data, ref tmpRemote);
listBox3.Items.Add(Encoding.ASCII.GetString(data, 0, recv));
String gt = data.ToString();
if (gt=="Welcome to the Server")
{
lb9.BackColor = Color.Green;
}
|
|
|
|
|
Hi,
what you need is called "debugging", which includes looking at intermediate values, and possibly rethinking your code.
Did you ever look at the value of gt?
Why is it you use Encoding.ASCII.GetString() to display something, however you use ToString() to compare it to a known value?
This is one occasion where less code will give you a better outcome.
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
modified on Sunday, June 12, 2011 9:11 AM
|
|
|
|
|
Hi
I have modified the code...Still the color does not change
String fr = Encoding.ASCII.GetString(data);
if (fr.Equals( "Welcome to the Server"))
{
lb9.BackColor = Color.Green;
}
|
|
|
|
|