|
I would like to change the border color of Text Box in C#. I subclassed the TextBox control and override the WndProc function to catch the PAINT Messages to draw the border with my color.
But the border color hasn't changed, still i am getting the default border color of text box that is Black color. The same code works fine with .NET 1.0 but not working in .NET 2.0 and the latest versions.
Can anyone tell what is the difference between .NET 1.0 painting and .NET 2.0 painting for TextBox?
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Drawing;
class MyTextBox : TextBox {
private const int WM_NCPAINT = 0x85;
private const int WM_ERASEBKGND = 0x14;
private const int WM_PAINT = 0xF;
[DllImport("user32.dll")]
static extern IntPtr GetDCEx(IntPtr hWnd, IntPtr hrgnClip, int flags);
[DllImport("user32.dll")]
static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
protected override void WndProc(ref Message message) {
base.WndProc(ref message);
if (message.Msg == WM_PAINT)
{
IntPtr hdc = GetDCEx(message.HWnd, (IntPtr)1, 1 | 0x0020);
if (hdc != IntPtr.Zero) {
Graphics graphics = Graphics.FromHdc(hdc);
Rectangle rectangle = new Rectangle(0, 0, Width, Height);
ControlPaint.DrawBorder(graphics, rectangle, Color.White, ButtonBorderStyle.Solid);
message.Result = (IntPtr)1;
ReleaseDC(message.HWnd, hdc);
}
}
}
}
Thanks in advance
|
|
|
|
|
I just tried your code with .NET 3.5 using VS 2008 and it worked ok, except that when I mouse over the textbox the border reverts to its original color
If its just the border style/color you want to change whats wrong with setting the BorderStyle and BorderColor properties?
|
|
|
|
|
There is no border color property for TextBox. The code which i shown in my initial post works fine if i put my textbox in the windows form. But it is not working with the custom form which i derived it from System.Windows.Form.
|
|
|
|
|
mutpan wrote: There is no border color property for TextBox
My bad.
Have you considered writing your own implementation of Textbox, or looking what else is around other than the native one.
|
|
|
|
|
J4amieC wrote: when I mouse over the textbox the border reverts
The textbox has all sorts of wierd behaviour when it comes to painting. In the past I've tried overriding OnPaint for a few things and it never behaved as expected. IIRC I gave up - always a good policy!
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) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Textbox behaves diffewrently because the .NET implementation is just a wrapper around the native draw code. For starters, to even get OnPaint to be called you have to SetStyle(ControlStyle.UserPain,true) but it still behaves weirdly.
In actual fact, online advice is to override WndProc as the OP has already done.
|
|
|
|
|
J4amieC wrote: is just a wrapper around the native draw code
Yeah, I figured that out way back when I was doing battle with it. It's about time they gave us a shiny new .net one . I did start creating one from scratch but I found quickly that it's far from trivial and wasn't worth the effort at the time.
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) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Hello
I'm building a windows application for our company, which checks the state of a list with web links. The proxy settings in our company are setted by an automatic configuration script. Is it possible to use these settings to st up WebRequests?
WebProxy proxy = WebProxy.GetDefaultProxy(); <- doesnt work.
Thanks for your help!
Best regards
succo
|
|
|
|
|
hi i m new in C#, and i have a dll, in dll some function are just like
public void hndRecordSave(project.frmMain f)
Member of BusinessLayer.Business
in which record save as data from textbox or combo box of a form, i just wana to know how this dll created, what the functioning behide that.
-----------------------------
i thinks u all don't understand my prob, so i m again trying..
i hav a project in which someone uses a dll, and suppose in this project a form (frmmain) contain some textboxes, combobox and some button also as save, delete..
and clicking on save- programmer just call
objDLL.hndRecordSave(this); //// as form name is same frmMain
and record saved
i just wana to know at ceating dll how he manage all form in function.
thanks again. hope u all understand what i want to say.
modified on Friday, June 26, 2009 5:54 AM
|
|
|
|
|
A dll can be created in C# by creating a Class Library project if that's what your asking.
Whoever wrote that dll is not the person to learn from though, passing a Form as a parameter is bad enough, but into a BusinessLayer
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) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
thanks for replying, but how can i create same dll and implement it again.
thanks
|
|
|
|
|
Use Reflector and hope the assembly is not obfuscated.
|
|
|
|
|
If it's a .net assembly, you may be able to disassemble it using Reflector[^]. To create your own, just choose Class Library when selecting the project type when creating a new project.
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) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
With one of my customers I have this really weird problem. I just describe it in a bunch of facts, to keep it short.
* It's an application that communicates with a weighbridge and visualises the current weight of the brigde (serial communication RS232) --> the scale sends over the weight continuessly
* The customer can make a ticket containing information about the transporter and the kind of product that's been transported
* When the ticket is saved, it is also printed on the connected USB HP LaserJet (P1006) printer
* pc/dev configuration: Windows XP SP3, VS2008 (C#)
The problem is that sometimes for an unknown reason, the printer does not print. The ready-LED keeps blinking but nothing happens. The application continues to work normal. When this happens, the customer opens the print cartridge cover and closes it again and then the printer starts the print job.
It's a problem that I've seen happening but I can not reproduce it.
it's not related to the data (if you print the ticket afterwards, no problem)
It's not related to hardware (did replace PC, Printer (from other brand), USB Cable without success)
I did rewrite my app so that the serial communication happens in a backgroundworker and generates an event only if the current weight is different from the previous value (this delegate for this event updates the GUI)
I did create also another backgroundworker to create and print out the document (System.Drawing is used to do this; did use Crystal Reports in the past but same problem there)
The data is stored in XML files
What I also did was unchecked the flag 'allow the computer to turn off this device to save power' for all USB Root Hubs. --> I don't have any results of that yet, since I did this just yesterday.
At this moment, I don't know where to search anymore. I can not reproduce it, I can not find any kind of pattern in the occurence of this problem, I can not tell what might cause the problem.
In summary: is there anybody with some suggestions
modified on Friday, June 26, 2009 3:56 AM
|
|
|
|
|
Sounds like an issue with the printer itself - possibly there's a bug in its software that you're hitting.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
|
Any collection is a valid data source for a data bound control, I thought.
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
|
|
|
|
|
Yes, I am aware of that, but is there a way to make use of the property binding to set the value in the control?
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
It's a collection of strings, you'd bind to the string, wouldn't you ?
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 Experts
i am using VS2005 and SQL Server 2005
i make a grid like asp.net gridview paging in winform datagridview.
i have 500000 record in make it fast so that user not to wait.
so i am using the paging in datagridview in winform
|
|
|
|
|
Sharma Dinesh Kumar wrote: so i am using the paging in datagridview in winform
Ok, so where is the prboblem?
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.
|
|
|
|
|
How to make a Datagrid view like ASP.NEt Gridview ....i want example
how make it
|
|
|
|
|
The GridView control is what you need. And, probably, a basic winforms book.
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
|
|
|
|
|
Sharma Dinesh Kumar wrote: i have 500000 record in make it fast so that user not to wait.
what is your requirement... what is the error you are getting... plzzzzzzz be clear while posting question...
|
|
|
|
|
Sharma Dinesh Kumar wrote: have 500000 record in make it fast so that user not to wait.
so i am using the paging in datagridview in winform
Sounds like a good plan. Reading a half million records at a time is obviously insane. Did you want an award, or did you have a question ?
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
|
|
|
|