|
I am trying to give the custom boder color for the text box in C#. I am using XP operating system and visual studio 2008. I have subclassed the Textbox and override the WndProc method to handle the WM_PAINT message to give the custom border color to the text box.
public class SampleTextBox : TextBox
{
public SampleTextBox()
{
BorderStyle = BorderStyle.FixedSingle;
}
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case 0x000F:
base.WndProc(ref m);
Control control = Control.FromHandle(Handle);
Graphics g = Graphics.FromHwnd(Handle);
ControlPaint.DrawBorder(g, control.ClientRectangle, Color.YellowGreen, ButtonBorderStyle.Solid);
g.Dispose();
break;
default:
base.WndProc(ref m);
break;
}
}
}
public class SampleForm : Form
{
public SampleForm()
{
BackColor = Color.SteelBlue;
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000;
return cp;
}
}
}
public class Form2 : SampleForm
{
private SampleTextBox textbox1;
public Form2()
{
textbox1 = new SampleTextBox();
textbox1.Location = new Point(50, 50);
this.Controls.Add(textbox1);
}
}
I am using WS_EX_COMPOSITED extened window style to my form to avoid the filckering because i am doing custom painting in my form. If i use WS_EX_COMPOSITED style with form , the border color of Text box comes with default color, that is black color while opening the form . But if i click and move the mouse in the non client area like border or titlebar of the form, the border color changes to color (Color.YellowGreen) which i specified in the Paint message of Textbox.
If I comment the "cp.ExStyle |= 0x02000000; /*WS_EX_COMPOSITED*/ " line, then the border always comes with the color what i specified in the Paint message of Textbox.
Can anyone please tell why this is happening and how can I achieve the custom border for the text box when WS_EX_COMPOSITED style applied to its parent control(form)?
Thanks in advance.
Mutpan.
|
|
|
|
|
Instead of WS_EX_COMPOSITED you can try like this to reduce flickering:
public class Form2 : SampleForm
{
private SampleTextBox textbox1;
public Form2()
{
this.SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.ResizeRedraw | ControlStyles.OptimizedDoubleBuffer, true);
this.UpdateStyles();
textbox1 = new SampleTextBox();
textbox1.Location = new Point(50, 50);
this.Controls.Add(textbox1);
}
}
|
|
|
|
|
using the styles "this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.OptimizedDoubleBuffer, true);" is not reducing the flickering in the non client area like title bar. So i should use WS_EX_COMPOSITED style.
|
|
|
|
|
i have a problem when i use the httpwebrequest for a page the page is displayed correctly and when but ispostback is always false.
i m sending the viewstate data too but it is still false
how can i make it to true so that i can access the full data.
the code is as follow
static CookieContainer cookieJar = new CookieContainer();
public string PostContenct(string dataPost, string srcuri)
{
Uri uri = new Uri(srcuri);
string data = dataPost;
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
request.CookieContainer = cookieJar;
request.AllowAutoRedirect = true;
request.Method = WebRequestMethods.Http.Post;
request.ContentLength = data.Length;
request.ContentType = "application/x-www-form-urlencoded";
StreamWriter writer = new StreamWriter(request.GetRequestStream());
writer.Write(data);
writer.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
int cookiecount = cookieJar.Count;
StreamReader reader = new StreamReader(response.GetResponseStream());
string str = response.StatusDescription;
string tmp = reader.ReadToEnd();
response.Close();
return tmp;
}
thanks
amirzada
|
|
|
|
|
Don't you think this question is more appropriate for ASP.Net forum.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
yea it is system.net class and can b used in both asp.net and c#
thanx alot i have made it.
thanx
amirzada
|
|
|
|
|
I have a variable
byte[] rxData;
And VS is complaining that it is unassigned. However i dont want to assign it as this is done in the switch statement that follows.
does anyone know why it still complains
;switch (rxMessage[3])
{
case 0x46:
for (int i = 4; i <= 1028; i++)
{rxData[i - 4] = rxMessage[i];}
break;
case 0x42:
rxData[0] = 0;
break;
case 0x4f:
rxData[0] = rxMessage[4];
break;
case 0x43:
rxData[0] = rxMessage[4];
break;
default:
throw new InvalidDataException("Error: Incorrect Subcommand type may have been found");
}
|
|
|
|
|
Hi,
maybe you have to initialise rxData first. It is set to null by default, but to assign values to the array (using an index like 0 at nul won't work). It must be initialised like this:
byte[] rxData = new byte[1024];
Regards
Sebastian
|
|
|
|
|
You have not defined the array.
byte[] rxData = new byte[someNumber];
|
|
|
|
|
Thanx For both of your answers this does allow the code to compile.
Was just hoping i could declaire it and give it a value in the switch without it complaining. The flow was being forced through the switch so though it would work.
Thanx for your time
|
|
|
|
|
gwithey wrote: Was just hoping i could declaire it and give it a value in the switch without it complaining. The flow was being forced through the switch so though it would work.
No, it wouldn't work: that is the whole point.
To cut down your code a little:
byte[] rxData;
rxData[0] = rxMessage[4];
You would still get your compile error, since rxData is null, thus rxData[0] does not exist. This is why the compiler complains.
byte[] rxData = new byte[1024];
rxData[0] = rxMessage[4];
Is fine, since rxData is no longer null, and rxData[0] (through rxData[1023]) exists and can be assigned.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Yeah that makes sense thanx it is clearer now
|
|
|
|
|
please any one can tell me how can i show a preview of the webcam video in a panel or picturebox using WIA or WIAVideo Li or in any other way.....
thanks....
|
|
|
|
|
Here is exactly what you want: [^].
The provided source code uses avicap32.dll, so if you want a WIA solution check this article: [^].
I hope these links help you,
Nuri
|
|
|
|
|
thanks for help...but in that way have to use a commen dialog box. isn't it? but i want to show my webcam preview in a panal or picturebox without using commen dialog box...is there a way to do that....?
A S E L A
|
|
|
|
|
S K Y wrote: but i want to show my webcam preview in a panal or picturebox without using commen dialog box...
I don't understand that.
The source code from the second link uses exactly the PictureBox control to show the captured video (picture by picture using timer). Please check out the provided source code for the article. The are 2 versions of the code available (for C# and VB). You can use the provided technique and place the PictureBox wherever you want.
Best wishes!
Nuri
|
|
|
|
|
hi...i couldn't download the zip file bcz got server error. do you have that zip file with you...(first article)
A S E L A
|
|
|
|
|
I also have the server error for the first article.
But i have downloaded and tested the source from the second one. It uses exactly the WIA, the PictureBox control and it is working! 
|
|
|
|
|
Bloody hell. You've been given explicit instructions, day after day. Perhaps you should just abandon this project ?
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,
When i click on a button ,it will check which version of mediaplayer is installed in that system. I am stucked here.What is the code for this in c#.
Pls help
|
|
|
|
|
string wmpExe = string.Concat(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), @"\Windows Media Player\wmplayer.exe");
if(File.Exists(wmpExe))
{
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(wmpExe);
}
|
|
|
|
|
Thanks for the replay, stancrm.
|
|
|
|
|
Hi rakesh312,
#1. Add a reference to your project point to \windows\system32\wmp.dll
#2. add this one in top of code :
using WMPLib;
#3 to get media player version is something like this :
WindowsMediaPlayer wmp = new WindowsMediaPlayer();
MessageBox.Show( wmp.versionInfo.ToString());
Good luck
|
|
|
|
|
How can i convert a List to Dataset?
Regards,
Alim
|
|
|
|
|