|
I'd like to disable mouse scrolling on the AutoScroll bars controls get.
I'm at a loss as to how to do this however.
Anyone know how?
cheers
Cata
|
|
|
|
|
As with many lower-level solutions, override WndProc and ignore (i.e., don't call base.WndProc ) the WM_MOUSEWHEEL (0x020a) message:
protected override void WndProc(ref Message m)
{
if (m.Msg != 0x020a) base.WndProc(ref m);
} Override this in a derivative of the class in which you want to disable the effects of the mouse wheel.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hey all. I suppose this is easy really, but I don't know how to do it.
How can I catch exceptions that occur in message handlers i windows forms? It's also gotta be before the default message pump exception handler.
I have some exceptions that can occur at a million places on user input, and should be handled centrally.
Thanks in advance.
|
|
|
|
|
Honestly, there's no reason an exception should be thrown to the message pump. Following the doctrine of "never trusting user input", all input should be validated prior to doing anything with it.
In any case, Application.ThreadException should typically do the trick. Even the event documentations states about what I said above, though. Always validate user input as close to the input as possible (i.e., the presentation layer or in methods and property set accessors that can be called by outside code).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'm working on some translation software that integrates third-party translation components, and the component sed to handle Japanese uses a non-Unicode encoding (Shift-JIS, for those in the know) that doesn't mashal all that easier to one of the stanford encodings supported by .NET. As a result, I need to open the Languages control panel and coach XP to assume that all non-Unicode text should be interpreted as Japanese.
However, when Japanese is selected, .NET strings that I think are storing German words don't display properly.
char umlautedU = 0x00FC;
char eszet = 0x00DF;
StringBuilder builder = new StringBuilder();
builder.Append("Schl");
builder.Append(umlautedU);
builder.Append(eszet);
Console.WriteLine(builder.ToString());
prints out Schlus to the console, although it DOES print out SchluB (where the u is really an umlauted u and B is the eszet which looks like the scripted capital B) just fine when the language for non-Unicode applications is set to English.
I'd always assumed that .NET strings printed correctly regardless of OS settings and the OS's treatment of non-Unicode strings. Anyone have any idea how to print German regardless of the language setting?
Thanks for your help,
Jerry Cain
jerry@cs.stanford.edu
|
|
|
|
|
I'm not sure I quite understand your question, but if you're printing to the console, you're grossly limited by the font support for the console. Even with Windows Forms you must use a font that contains glyphs for the character you want. Some font formats will specify what character sets they support. See a previous thread where I posted some code for EnumFontFamilies(Ex) that enumerated this information (all chracter sets for all font families).
Now, what I think you're asking is how to display one culture in the UI while the OS is set to another. This is done by setting Thread.CurrentCulture to a CultureInfo (like new CultureInfo("de-DE") for German region and language) for regional settings (dates, times, numbers) and Thread.CurrentUICulture for determining which CultureInfo classes like the ResourceManager and ComponentResourceManager should use for resolving resource files (that would contain localized strings and other types with TypeConverter s that can convert from/to strings).
If you've used the designer to localize an app (bad idea with VS.NET 2002 and 2003 which uses the ResourceManager , as the number of calls necessary adds a lot of size to your assembly and slows performance; VS 2005 will use the ComponentResourceManager which is more efficient in the way it works), then you have to set Thread.CurrentUICulture before InitializeComponent is called. If you want to swap languages at runtime, you need to extract the initialization code (not the instantiation code, though - you only want to instantiate controls and support types once) and call a method that re-runs that code (basically).
Be sure to read Developing World-Ready Applications[^] in the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
How can i show a border(highlight) around a control that is selected by a user. And how can controls be resized by using mouse.
Please let me know.
Thanks
smartyosu
|
|
|
|
|
when i align the tab control to left or write the text on the tabs doesnt apear at run time ? (the tab text is empty)
|
|
|
|
|
Hi,
I am working on a windows application where the user should be able to move,resize and drag and drop a control (a picture box in my case). I have both MouseDown and Click events for this control. But I cant really use the Click event because everytime I press the mouse button on the control the MouseDown event fires up. Is there a way that i can differentiate between MouseDown and Single Click. Please let me know.
Thanks
smartyosu
|
|
|
|
|
Use a timer. The actual implementation should be placed in the timer event handler (just depends on which Timer class you use; for example, the System.Windows.Forms.Timer.Tick event). The MouseDown event handler starts the timer. If the timer elapses, your original MouseDown implementation is executed. The Click event handler should stop the timer. The timer duration should be a single occurance (non-repeating) and should be at least SystemInformation.DoubleClickTime (an extra 10 milliseconds should be plenty in case of lag).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
How can I make an event handler for every time a certain method "Send" is called?
Or actually event better. An event handler for when a new item is added to a listbox.
/\ |_ E X E GG
|
|
|
|
|
The event pattern in .NET is quite easy. The correct approach is define a delegate (using EventHandler or some EventHandler -like syntax (like delegate void MyEventHandler(object sender, MyEventArgs e) ). Then you declare your event on your class, as well as define an OnEventName method.
The naming convention follows: for an event name "MyEvent", you define a delegate and members like so:
delegate: MyEventHandler
arguments: MyEventArgs
event name: MyEvent
handler: OnMyEvent
So an example class would look like this:
public delegate void SentHandler(object sender, SentArgs e);
public class Example
{
public event SentEventHandler Sent;
protected virtual void OnSent(SentEventArgs e)
{
if (Sent != null)
Sent(this, e);
}
public void Send(string message)
{
OnSent(new SentEventArgs(message));
}
}
public class SentEventArgs : EventArgs
{
string message;
public SentEventArgs(string message)
{
this.message = message;
}
public string Message
{
get { return message; }
}
} You define a protected virtual member named OnEventName so that derivative classes can override it (and they should call base.OnEventName ) without handling the event, which require far more IL statements and doesn't allow for as much handling (like the ability to not have the base handler called, which is actually what raises the event).
This is also documented in the .NET Framework SDK.
What you want to do for a ListBox isn't at all easy. While you can extend ListBox and ListBox.ObjectCollection to override ListBox.CreateItemCollection and return your own ListBox.ObjectCollection derivative, you can't override Add , Remove , etc. While you could hide them using new , your definition won't be called because the ListBox internally refers to the ListBox.ObjectCollection class.
With member hiding, the call is not virtual. This means that in order for your implementation to be called, your class must be the class that's referred to. The following example should demonstrate better:
public class Test
{
static void Main()
{
Test t = new Test();
t.A();
t.B();
t = new Test2();
t.A();
t.B();
((Test2)t).A();
((Test2)t).B();
}
public void A()
{
Console.WriteLine("Test.A");
}
public virtual void B()
{
Console.WriteLine("Test.B");
}
}
public class Test2 : Test
{
public new A()
{
Console.WriteLine("Test2.A");
}
public override void B()
{
Console.WriteLine("Test2.B");
}
} This would print the following to a console:
Test.A
Test.B
Test.A
Test2.B
Test2.A
Test2.B So, as you see, unless it's Test2.A being called instead of Test.A when hiding the member, Test.A is called. This is the difference between the call IL instruction that is executed for A() where the callvirt IL instruction is executed for B() .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I'm looking for a control which is similar to the gradient bar seen when windows starts up. Yes, the one where the colors move from left to right. I'm pretty sure I've seen it somewhere around, but can't find it anymore.
Thanks for any help.
Matthias
If eell I ,nust draw to your atenttion to het fakt that I can splel perfrectly well - i;ts my typeying that sukcs.
(Lounge/David Wulff)
www.emvoid.de
|
|
|
|
|
Dear sir,
i want to navigate between different controls in my windows form using enter key. how it is possible. all the events that i hve see is for specific object like form keydown event whenever focuss chage to another child control this event dose't work.
thnx alot.
farukhalifarooq
|
|
|
|
|
You could override the PreProcessMessage method of either the Control or the Form.
Roughly
public override bool PreProcessMessage(ref System.Windows.Forms.Message msg)
{
Keys keyCode=(Keys)(int)msg.WParam & Keys.KeyCode;
if((msg.Msg==WM_KEYDOWN || msg.Msg==WM_KEYUP) && keyCode==Keys.Enter)
{
msg.WParam=(System.IntPtr)0;
return true;
}
}
Michael
CP Blog [^]
|
|
|
|
|
Or even easier: set Form.KeyPreview to true and override the Form.ProcessDialogKey message:
protected override bool ProcessDialogKey(Keys keyData)
{
if (keyData == Keys.Enter)
{
SendKeys.Send("{TAB}");
}
return false;
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello C# Guru´s!
I´ve a serious problem with array´s and reflection.
I have a assembly source something like that:
namespace Test
{
class TestClass
{
public int intTest1;
public float fltTest1;
public int[] arrTest;
// default constructor
TestClass()
{
arrTest = new int[12];
}
}
}
For each instance a default constructor defines the array 'arrTest'.
I read MetaInforation from this dll and instanced a object from this class.
Then I walk through every Field and do something.
But if the field is an array I would do something before, and for that I need the Length of the array.
I tried following lines:
using System;
using System.Reflection;
namespace Test
{
class MainClass
{
[STAThread]
static void Main()
{
Assembly assembly = System.Reflection.Assembly.LoadFrom("Test.dll");
foreach(Type tmpType in assembly.GetTypes())
{
if (tmpType.IsClass)
{
MethodInfo[] m = tmpType.GetMethods();
object myInstance = tmpType.InvokeMember(m[0].Name, BindingFlags.Default | BindingFlags.InvokeMethod, null, tmpType, null);
foreach (FieldInfo tmpField in tmpType.GetFields())
{
if (tmpField.FieldType.IsArray)
{
PropertyInfo p = tmpField.FieldType.GetProperty("Length", typeof(int));
int arrLength = (int) p.GetValue(tmpField,null);
// ************************************* //
}
// do something
}
}
}
}
}
}
Compile and Link is no problem...
But if I debug the lines it stops at // *********
with an Exception: The target object does not match (or something like that)
Why? I can´t help myself anymore, what did I wrong?
Please help me...
With regards
Norman-Timo
|
|
|
|
|
Norman-Timo wrote:
what did I wrong?
How about passing the object instance rather than the type
int arrLength = (int) p.GetValue(myInstance,null);
top secret xacc-ide 0.0.1
|
|
|
|
|
Thank´s for your reply!
But this is the first thing I tried!
I only get an exception that the target object does not match
I tried every object which is thinkable but alway´s the exception.
Maybe there´s another (nicer) way to get the array length? But the Method 'GetValue(obj,null)' does not work!
Maybe somone has another idea of getting the arrayLength via reflection???
Please answer
Norman-Timo
|
|
|
|
|
I'm probably missing something increadibly simple. Bascially, I've been playing with MySQl and want to output my queries in a console.
If I run a console app, that's no problems. But if I create a windows app, it doesn't work. Right now I have it set up so that you click a button a connection to the sql server is made. Then I sorta expected a console to pop up and display some query information. Then I close the connection.
The connections are working. I verified that. But Console.Writeline just doesn't display any output. Is this because I created a windows app and not a console app?
As a next step I'm thinking of creating a text box and displaying the query in there. But I just wanted to ask about my console problems.
|
|
|
|
|
Console class only works on console application... if you want just to test your application and show some message use a message box....
MessageBox.Show("Test Message");
Works as well...
cya
Wender Oliveira
.NET Programmer
|
|
|
|
|
|
If you want console output to be visible when used in a Windows Forms application, you have to build the executable as a console app (with /t:exe instead of /t:winexe to the csc.exe command-line compiler, for example). This will start a console window then start your Windows Forms application. Any time you use any of the Console methods, that initial console window is what is being referred to; otherwise, there is no console for the Windows Forms application. It's a completely different subsystem.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Okay cool. Thanks everyone. I was thinking of using a text box actually and having stuff display in there. I was using MessageBox for some lines butn it didn't work for others.
I just assumed that if you called a console window in c# that a console window would pop up. even if calling from a window app. Oh well.
|
|
|
|
|
I'm having some trouble implementing drag & drop between two treeviews in two different winform applications.
It works just fine between two treeviews in the same application though.
What I do is this:
<br />
private void OnDragDrop(object sender, System.Windows.Forms.DragEventArgs e)<br />
{<br />
...<br />
if (e.Data.GetDataPresent(System.Type.GetType("MyNameSpace.MyTreeNode2")))<br />
{<br />
data = (MyTreeNode2)e.Data.GetData(System.Type.GetType("MyNameSpace.MyTreeNode2"));<br />
<br />
if (data != null)<br />
MyTreeNode2 newFolder = (MyTreeNode2)data.Clone();<br />
<br />
...<br />
}<br />
(The MyTreeNode2 class is inherited from the standard TreeNode class, adding only some extra properties)
This will work fine when doing it with strings, probably since the format for strings is well understood or
something while the format of my treenode object is not so easily shared between applications. Do I need to
implement some kind of serialization stuff for my object for this to work, and pass the string? I know that there
are a couple of predefined data formats available, but in java with WFC (which is where I've just this method
before and it worked better I used the object type DataFormats.CF_WFCOBJECT and it worked fine. Is there a corresponding
solution implemented in .NET/C#?
(It works for a single child node in my treeview, but not for a folder with child elements...)
Can anybody help me?
|
|
|
|