|
crushinghellhammer wrote:
Is there a more elegant way of doing this
Nope, that's about it. You could write a class factory of sorts that would take care of this for you, depending on what you are doing that may be overhead.
- Nick Parker My Blog | My Articles
|
|
|
|
|
Hi,
I'm trying to get a custom control to render its contents into a bitmap by sending it a WM_PRINT message. This works great if XP themes are not enabled. If XP themes are enabled, some controls (textbox, listview, listbox, treeview, datetimepicker) forget how to draw a themed border and draw an unthemed 3d border instead - and the groupbox only draws its background
Any ideas on how to get round this?
"I think I speak on behalf of everyone here when I say huh?" - Buffy
|
|
|
|
|
First, don't handle the WM_PAINT message. Override OnPaint for your controls (unless you're using an IMessageFilter or something) and use Control.SetStyle with the ControlStyles enumeration (read the .NET Framework SDK documentation for details) to control exactly what gets drawn.
If you don't want this code to run on Windows XP, use the Environment.Version property to determine on what platform and version of the OS the environment (the CLR) is running. Use that as a condition to executing certain code.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have a number of controls that are interacted with using mouse events. These work fine until the area they are in is scrollable, then, because they are tied to the screen location rather than the parent client area location, they don't function properly.
How would I calculate the location in relation to the parent instead?
Seems like a simple thing, but i'm mildly confused by it.
Regards
Cata
|
|
|
|
|
|
Thanks Nick, but that didn't solve the problem.
I tried point to client using the parent panel calling the method using the screen point taken from the control. This works the same as before however.
The problem I have is with scrolling. The client area remains the same, even if the client area has been scrolled down or across. This means that the information I am getting is still out of sync with the display. I can't find a way to get the X and Y values of the scrollable client.
I.e. if i scroll halfway down both X + Y axis, it still tells me I'm clicking on coordinates {300, 375}, when it should say i'm on {5300,5375}.
Any other ideas?
Cata
|
|
|
|
|
Hi,
I want to update both the contents and the checked state of items in a CheckedListBox on the ItemCheck event. It turns out that when removing an item that occurs before the checked item (the one that is being processed), both this checked item and the one after it will appear to be checked after the event finishes. To illustrate, here is some code that first populates a CheckedListBox with a sequence of integers (named checkedListBox), and then when an item is checked, removes this item, and also checks the previous item if it was even, or the following item if it was odd.
private void checkedListBox_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e)
{
// get the currently checked index
int checkedItemIndex = (int)checkedListBox.Items[checkedListBox.SelectedIndex];
bool checkedEven = checkedItemIndex % 2 == 0 ? true : false;
// remove the event handler for now - it is triggered by SetItemCheckState
checkedListBox.ItemCheck -= new ItemCheckEventHandler(checkedListBox_ItemCheck);
// if it was an even number, check the previous index
// ie - checking 4 will result in 3 being checked
// else, check the following index
// ie - checking 5 will result in 6 being checked
if (checkedItemIndex > 1 && checkedEven)
checkedListBox.SetItemCheckState(checkedItemIndex - 1, CheckState.Checked);
else if (checkedItemIndex < checkedListBox.Items.Count - 1)
checkedListBox.SetItemCheckState(checkedItemIndex, CheckState.Checked);
checkedListBox.ItemCheck += new ItemCheckEventHandler(checkedListBox_ItemCheck);
// remove the currently clicked index
checkedListBox.Items.RemoveAt(checkedItemIndex);
}
// here is the code to populate the box
private void resetListBoxContents()
{
checkedListBox.Items.Clear();
for (int i=0; i < 20; i++)
checkedListBox.Items.Add(i);
}
As you see, when checking 9, 9 is removed and 10 is checked. But when 4 is checked and removed, 3 becomes checked, as it should be, but so is 5, which should not be.
Any help in this matter would be greatly appreciated. Thanks!
|
|
|
|
|
Just a question, what is the purpose of having the check box if the item disappears as soon as you click on it?
- Nick Parker My Blog | My Articles
|
|
|
|
|
In actual use, probably none - I've only used to illustrate the problem I've been having. In the real implemenation, I'm removing entries from the box which are mutually exclusive with the checked item.
The problem seems to be that the check gets set after the event has finished, and instead of applying it to the clicked item (which may have moved in this case), it checks the index of where that item originally was. Does this make sense?
Perhaps there is another control I can use to facilatate this behavior?
|
|
|
|
|
Found the solution - when editing the state of the currently checked item, do so through the ItemCheckEventArgs parameter. Easy fix.
|
|
|
|
|
I am writing a custom grid, inherited from datagrid. I use data-binding to populate grid from an ArrayList.
When I click the column header, I am capturing the click and sorting the arraylist and re assign the data source to populate grid with sorted data.
My problem is, I do not get the sort arrow in the column header. How can get this?
Thanks in advance.
- TOJO
|
|
|
|
|
Hi everybody,
I need a control that allows the user to select between n columns to show in a grid / listview. Much like the ones seen in e.g. Outlook where you have a list of available columns in a left hand list and a right hand list with the ones you have selected. In between there is buttons used to move "columns" from one window to the other, one at the time or all of them.
I've searched the net, looked through the C# controls list here on CP - but with no luck. Does anybody know of such a control, or is this a candidate for my first CP article ?
Thanks in advance - have a nice day !
/Jan
Do you know why it's important to make fast decisions? Because you give yourself more time to correct your mistakes, when you find out that you made the wrong one. Chris Meech on deciding whether to go to his daughters graduation or a Neil Young concert
|
|
|
|
|
You and I must of woke up this morning with the same mission. I'm looking for one of these controls myself in C#. I wrote one (although not as fancy as the one in Outlook) in MFC/C++ years ago and may end up "porting" that one if I can't find one that's already freely available. Let me know what you turn up and I'll do the same.
|
|
|
|
|
Jan R Hansen wrote:
Does anybody know of such a control, or is this a candidate for my first CP article ?
You could write this up as an article. I haven't seen any controls on CP that do what you are asking so it should be fair game. I had written a control about a year ago doing just this for a project, which was simple enough but I no longer have the source to send you. It should simply be a process of finding the selected items in one side and adding them over to the other - don't forget to remove them from the first side then. If you have any questions feel free to ask.
- Nick Parker My Blog | My Articles
|
|
|
|
|
Hi all
I have a problem with my program, I'm trying to send data between two computers. The problem is this, I can send data between the client app and server app (which is on my other computer, through wirless connection) as long as I specify the HostName i.e. "dave", then use the IPHostEntry.Resolve to get the ip address. I don't want to use the HostName as the app will run over the internet, so my client app sends it's ip address to the server, the server then try's to send data back to the client using the given ip address but gets stuck in a loop as it keeps sending itself the data not the client. When I had a look at the ip address the server was recieving it ok but when i had a look at the HostName that the server was producing from the ip address, it was refering to itself not the client.
Would this be anything to do with the fact that its over a local network and not the internet?
My Server Code is below:
TcpClient tcpc = new TcpClient();
int port = 5656;
string[] server = o.WhosOnline();
IPHostEntry IPHost;
string []aliases;
bool loggedin = false;
IPAddress[] addr;
bool success;
success = o.loguser(cmd[2].ToString());
//IPHost = Dns.Resolve("dave") <-- I DONT WANT TO USE THIS
IPHost = Dns.GetHostByAddress("192.168.0.1"); <-- I NEED SOMTHING LIKE THIS
Console.WriteLine("Host Name: " + IPHost.HostName); <-- DISPLAYS SERVER NAME
aliases = IPHost.Aliases;
Console.WriteLine(IPHost.AddressList[0].ToString()); <-- DISPLAYS CLIENTS IP
addr = IPHost.AddressList;
IPEndPoint ep = new IPEndPoint(addr[0], port);
tcpc.Connect(ep);
// Get the stream
Stream s = tcpc.GetStream();
StreamWriter r = new StreamWriter(s);
r.Write(stream);
r.Flush();
r.Close();
s.Close();
tcpc.Close();
Console.WriteLine("sent");
Can anyone help?
|
|
|
|
|
If you don't want to hardcode the computer name, use Environment.MachineName . Call Dns.Resolve on that.
With the continuous rise in firewall adoption, you should not expect the server to be able to send a client information without a connection already being established. A client request/server response protocol is most prevalent in everything you do today, from SMTP, POP, IMAP (mail protocols) to HTTP and various IM protocols (all over SSL, which is also client request/server response-based).
Communications should occur like so:
Client creates a connection to the server, which the server optionally accepts (maybe it's a blocked IP or something). The client sends commands to request or post data. The server responds with an error or success code and sends the requested data or status back to the client. The client disconnects.
Because of firewalls - and especially NAT'ing firewalls (network address translation, which typically use reserved IPs that don't resolve on the Internet like the 192.168 subnet you're IP address is) - the server can't respond directly to the client without a connection already existing. There are some protocols supported by some firewalls (like VPN) that may allow this, but these are not trivial to implement.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for the reply
So what your saying is that i should not close the connection when the client has sent its data to the server so that the server does not have to connect to the client to send data back.
Would this mean that the server would use a lot of resources if there were multiple connections to it?
|
|
|
|
|
Hi everyone, I'm trying to export into a csv file from the dataset. But i'm not using Button. I'm asking the user to check on the check box if they want to export the file. If they checked that checkbox, as i go through the form and grab data through my sql statement (and the data are now in the dataset, with two table, but i only want to export one table), at the end i would like to send those data to the csv file. And i have done some research but couldn't find much on what I'm doing. Does any one have any C# sample code links or give some suggestion in the coding, i'll be very appriciated. This is totally new to me, so i'm asking for everyone's help. Thanks in advance for your time.
Cheers!
*HyVong*
|
|
|
|
|
One way is to use XSLT to transform the dataset xml into a csv format.
You could of course just iterate through the dataset and write to a file yourself.
|
|
|
|
|
|
I'm thinking of starting a new project in C#. Or should I wait til 2005 when Visual Studio 2005 (C# 2.0) is released so I wouldn't have to rewrite a lot of code ? How big will the incompatibility between C# 1 and C# 2.0 be ?
Regards, Desmond
|
|
|
|
|
hi Desmond,
I do not feel MS will make such a drastic change in the language
for C# 2.0. I feel they will add support for Generics (Templates ) , Closures etc. ( All these VM languages are introducing back those
features of C++ they thrown away earlier )
IMHO , Stick with C# 1.x and if at all u need to change , it will
be some methods in the new BCL or some of the current classes might be made
deprecated ( As sun often does ! )
Praseed Pai
www.praseedpai.com
|
|
|
|
|
SOCM_FP_CPP wrote:
I do not feel MS will make such a drastic change in the language
for C# 2.0. I feel they will add support for Generics (Templates ) , Closures etc.
You don't think generics are going to be drastic?! Have you been reading everything we are going to get and the impact it will make?
- Nick Parker My Blog | My Articles
|
|
|
|
|
hi Nick ,
Ur right !. Generics are a welcome addition to the C# language. Perhaps
it will change the way we program our data structures and other stuff.
I was anwsering the questions from a code maintanence point of view.
he was more worried about porting C# 1.x to C# 2.0.
Praseed Pai
www.praseedpai.com
|
|
|
|
|
You won't need to rewrite code. There are no breaking changes in the C# language specification, only new support is added. Almost all the classes supported in the .NET BCL (base class library) will be supported as well (I can't say for sure: there's hundreds of classes).
And don't forget the .NET runs side-by-side. I currently have 1.0 SP2, 1.1, and 2.0 Beta installed. If a managed application that targets 1.0 is installed and .NET 1.0 is installed, it will run against that (unless you redirect). If .NET 1.0 is not installed but 1.1 is, it will run against that (it uses the correct or newer Framework by default). You can control this behavior, however. Read Deploying Applications[^] and Configuring Applications[^] in the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|