You have two problems. Firstly, the first parameter to SetSysColors is the number of colours you are changing, so it should be 1 instead of 0. Secondly, the second and third parameters should be passed by reference rather than by value (they are actually both pointers to the first element of an array). Changing the declaration to [DllImport("user32.dll")] public static extern int SetSysColors(int nChanges, ref int lpSysColor, ref int lpColorValues);
and the call to int iElement = 4; int iColor = 13160660; iRes = SetSysColors(1, ref iElement, ref iColor);
should make things work. Chris Jobson
Chris Jobson
Posts
-
Change title bar color (or menu) -
DrawString on MDI background??I don't know if there's a "proper" way to do this, but a workround I've found is to draw the text on a bitmap then assign this bitmap to the MDI window's BackgroundImage property. A snag is that you have to re-create the bitmap whenever the window size changes or it gets tiled (actually you probably only need to recreate it if the window gets smaller, but I haven't tested this). For example, putting the following code in the MyMDIForm_Load and the MyMDIForm_Resize event handlers works:
Bitmap bm = new Bitmap(ClientSize.Width, ClientSize.Height); Graphics gr = Graphics.FromImage(bm); gr.FillRectangle(new SolidBrush(Color.Yellow), 0, 0, bm.Width, bm.Height); gr.DrawString("The cat sat on the mat", Font, new SolidBrush(Color.Red), 50, 50); BackgroundImage = bm;
Chris Jobson -
ListBox and DataSourceMehdi, If you add the code I gave, or the following modified version of it, at the end of the TransferItem method in your previous posting it should work:
CurrencyManager cm = BindingContext[ListBoxA.DataSource] as CurrencyManager; if (cm != null) cm.Refresh(); cm = BindingContext[ListBoxB.DataSource] as CurrencyManager; if (cm != null) cm.Refresh();
Chris Jobson -
How to set the TIMEOUT property of WebClient class???Sorry, I thought that WebClient had a way to access the WebRequest that it was using internally - but I was wrong, so maybe you will have to use WebRequest/WebResponse:(. The only other idea I have is that if you know in advance the URLs you will be accessing you could use WebRequest.RegisterPrefix to register a class of your own (for just the URL you want) that implements the IWebRequestCreate interface, and that class could return an instance of one of the standard WebRequest objects (e.g. an HttpWebRequest) with the timeout set to whatever you want. See the web page I referenced in my previous answer for more details. However, I must stress that I haven't tried this, and it's based only on my understanding of the information on the www.dotgnu.org website. Good luck! Chris Jobson
-
How to set the TIMEOUT property of WebClient class???The System.Net.WebRequest class has a Timeout property, which is a value in milliseconds or System.Threading.Timeout.Infinite. See http://www.dotgnu.org/pnetlib-doc/System/Net/WebRequest.html[^] for more details of the class. Chris Jobson
-
GetLocaleInfo for .NET?I think the CultureInfo class (from System.Globalization) might be what you're looking for. Chris Jobson
-
ListBox and DataSourceOne method that will work is to invoke the Refresh method of the Currencymanager objects involved, e.g. after you've moved an object from one ArrayList to the other:
CurrencyManager cm = BindingContext[USStatesA] as CurrencyManager; if (cm != null) cm.Refresh(); cm = BindingContext[USStatesB] as CurrencyManager; if (cm != null) cm.Refresh();
A nicer method might be to wrap the ArrayLists (or derive from them) in an object of your own which implements the IBindingList interface. This allows an event to be raised when the list is changed, and I assume that the CurrencyManager traps this event and automatically updates the bound controls (but this is based only on my understanding of the documentation - I haven't tried it :~ ). Chris Jobson -
Error in .NET (regions) ??!!I've found by experiment that the problem is with the width (0.002...). If either the width or the height of the rectangle used to create the region is less than 0.03125 then the problem occurs. I've also found that
region.IsEmpty(myform.CreateGraphics())
returns true if either the width or height is less than this value. I'm afraid I've no idea why a width/height of less than 0.03125 makes a region empty, or what you can do about it (except check for a size less than this and make it bigger). 0.03125 = 1/32, so maybe this is some "magic number" used within GDI+?:confused: Chris Jobson -
flatstyle, buttons with bitmaps, and transparencyAre you assigning the bitmap directly to the Image property or using an ImageList (by setting the Button's ImageList and ImageIndex properties)? I've found that if I use the Image property there's no transparent colour, but if I put the bitmap in an ImageList then I can specify the colour to be treated as transparent in the bitmap. Good luck! Chris Jobson
-
sunken vs. raised status bar border styleThey have an effect on my system (Win2K). Maybe it depends on the oiperating system in use? Chris Jobson
-
How to assign executable's iconSelect the project in the Solution Explorer, right-click and select properties, and there is a line for Application Icon. However, if it's a WinForms application the icon shown in the taskbar will be the one given by the main form's Icon property. Chris Jobson
-
LISTBOX How to select more than one entry at the startupAssuming that you have set the SelectionMode to MultiSimple or MultiExtended, code similar to the following will work:
//Unselect all items (not needed if you've only just created the ListBox) listBox1.SelectedIndex = -1; //Select second, fourth, ..., items (each time a new item is assigned to //.SelectedItem that item is added to the collection of selected items) for (int i = 1; i < listBox1.Items.Count; i += 2) listBox1.SelectedItem = listBox1.Items[i];
Chris Jobson -
Inserting a tabpageI don't know of a way to do it directly, but it's fairly easy to do by shuffling the tab pages around. For example:
private static void AddTabPageAtIndex(TabControl tc, TabPage tp, int index) { // Get index into sensible range if (index < 0) index = 0; else if (index > tc.TabCount) index = tc.TabCount; // Add a dummy page to the end tc.TabPages.Add(new TabPage()); // Copy tab pages that are to be after new one for (int i = tc.TabCount-1; i > index ; --i) tc.TabPages[i] = tc.TabPages[i-1]; // Insert the new page tc.TabPages[index] = tp; }
Chris Jobson -
String Manipulations.Replace("\"", "")
will remove all the double-quote characters in s. Chris Jobson -
String ManipulationMaybe I'm missing something, but do you need the quotes at all (i.e. do any of the strings contain embedded commas)? If not then why not remove all the quotes first (using Replace), then use Split to break up the line on the commas? If the strings can contain embedded commas then it's harder. You say that it "throws in extra quotes whenever it wants", but then in your example its actually omitted a quote as well (between 'test' and the comma immediately after it). Does this really happen or was this an error in the example? Also, can it really add extra quotes "anywhere" (including in the middle of the text strings), or does it simply replace one quote by one or more quotes? Knowing the exact nature of the problem would help in trying to find a solution. Chris Jobson
-
delegates=strong refs?I think the solution is that if your usercontrol hooks itself to the parent's events it should also unhook itself. If you remove the control from its parent the control will get a ParentChanged event and the Parent will now be null. For example, the following code within the user control seems to work: private Control parent = null; private MouseEventHandler meh = null; private void UserControl1_ParentChanged(object sender, System.EventArgs e) { // Unhook from previous parent (if any) if (parent != null) { parent.MouseMove -= meh; } // Remember new parent parent = Parent; // Hook new parent (if any) if (parent != null) { if (meh == null) meh = new MouseEventHandler(parent_MouseMove); parent.MouseMove += meh; } } Chris Jobson
-
Creating a new From in an eventhandler of a form, the event is invoked by another thread.I think a better way might to be to use the InvokeRequired() and Invoke() methods in the OnMessageReceived method to marshal the event to the GUI thread. You should then be able to create and display the new form with no problems. See the article http://www.codeproject.com/cs/miscctrl/TSWizard.asp[^] for some examples of this. Chris Jobson
-
Double bufferingI think that the problem is that your painting code (which I assume is in the Paint event handler) should use the Graphics object from the PaintEventArgs parameter rather than creating its own. This seems to fix the problem. Chris Jobson
-
System ShutDown...Hi, I think that OnShutDown should check that there is a handler for the event, i.e. the code should be: if (ShutDown != null) ShutDown(this, e); Chris Jobson
-
Select Boxes or Inverse Color PensThere are some methods in System.Windows.Forms.ControlPaint that look as though they might be useful (DrawReversibleFrame, DrawReversibleLine, FillReversibleRectangle), but I haven't tried them. Chris Jobson