|
I believe so sir! thank you very much
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
Hey guys,
im trying to implement a specific Panel-Control, to which one can only
add RadioButtons (or any other Control that is wanted).
Because im working on a kind of designer its very important that it would be possible
to add every other kind of control but only RadioButtons shall be accepted and thus be really added.
I tried to understand how all the panel-calls work and ended up in trying to change the OnControlAdded-method:
protected override void OnControlAdded(ControlEventArgs e)
{
if(e.Control is RadioButton)
{
base.OnControlAdded (e);
}
else
{
try
{
base.OnControlAdded(new ControlEventArgs(e.Control));
base.Controls.Remove(e.Control);
}
catch(Exception ex)
{}
}
}
The problem is, that it works quite good (even though it sucks, that the control is first added and then removed...) but I get an error after the method is left.
It seems that another method, which is not visible to me, tries to access the removed Control and thus trows an error (System.ArgumentException: ControlCollection.GetChildIndex(Control child..)).
I tried working out which method this could be but ended nowhere.
It would be nice if you could give me a small hint and some help
Any help is appreciated,
Matthias Rost
|
|
|
|
|
Does the stack trace reveal the source of the exception?
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Well, I hope that helps:
Piped error: System.ArgumentException: 'child' is no subisdiary Control of this superior Element.
at System.Windows.Forms.ControlCollection.GetChildIndex(Control child, Boolean throwException)
at System.Windows.Forms.ControlCollection.GetChildIndex(Control child)
at System.Windows.Forms.ControlCollection.setChildIndex(Control child, Int32 newIndex)
at System.Windows.Forms.Design.ControlOleDragDropHandler.OnInitializeComponent(IComponent comp, Int32 x, Int32 y, Int32 width, Int32 height, Boolean hasLocation, Boolean hasSize)
at System.Windows.Forms.Design.OleDragDropHandler.CreateTool(ToolboxItem tool, Int32 x, Int32 y, Int32 width, Int32 height, Boolean hasLocation, Boolean hasSize)
at System.Windows.Forms.Designs.ParentControlDesigner.CreateToolCore(ToolboxItem tool, Int32 x, Int32 y, Int32 width, Int32 height, Boolean hasLocation, Boolean hasSize)
at System.Windows.Forms.Design.ParentControlDesigner.CreateTool(ToolboxItem tool, Rectangle bounds)
at System.Windows.Forms:Design.ParentControlDesigner.OnMouseDragEnd(Boolean cancel)
sincerely yours,
Matthias Rost
-- modified at 11:28 Sunday 21st May, 2006
|
|
|
|
|
Yes, that explains what's happening. It seems that the framework is handling the end of the drag and drop of the control from the toolbox to your panel, and running into problems because the control it expects to operate on has been deleted.
I recommend posting a message to the panel (when the control is added) which delays the execution of the added control's removal. That way, your control will be removed after the framework has had a chance to complete its normal processing of events.
It would've been nice if ControlEventArgs exposed a bool that you could set to disallow the operation. That would've allowed you to elegantly restrict the type of controls your panel accepts.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Yes, I think you're pretty right...
I will try to maybe catch the Event when dragndrop is ended and then will remove it.
Otherwise I will use a timer as you have proposed.
Thanks for that hint, I should have seen it by my own
greetings,
Matthias Rost
|
|
|
|
|
Subfreq wrote: I will use a timer as you have proposed.
Actually I wasn't suggesting using a timer. I believe you can delay processing of an event (a la Win32 PostMessage() vs. SendMessage() ) by using BeginInvoke() . See this[^] excellent article for more information.
When you've got it work, maybe you can post an article on the subject at CP!
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Ah, I got your idea
Looks very interesting!!!
Thanks for your great help, and yes, if it works very well, I think I will do a little
article (as its really just very small).
Again, thank for your support
Matthias Rost
Edit: It works just perferctly, Thanks, Thanks, Thanks!
-- modified at 12:33 Sunday 21st May, 2006
|
|
|
|
|
Hi,
I'm just starting to use C# after several years of C++ and there are quite a few confusing things.
For ex. if I'd like to write a function that sums two objects for which there is an operator+, how should I do that? I tried to do something like this, but ofcourse it's not correct.
<br />
Object sum(Object a, Object b)<br />
{<br />
return (a.GetType())a+(b.GetType())b;<br />
}<br />
So what it the way things in C# should be written, if it something for one would use templates in C++?
Thanks,
Greg
|
|
|
|
|
You need to know of which type a,b is.
You can check it like this:
if(a is MyType && b is MyType)
{
return (MyType)a + (MyType)b;
}
I'm not sure if the abstract GetType()-way will work.
For templates you might want to take a look at Generics
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thanks, but the point is I can not tell the types beforehand, so I'd like to make it work for any type that has the appropriate methods, operators, etc.
If it changes anything, the function would be some non-static method of a class for which further specializations are likely to take place.
Generics sound nice, but for now I'd like to stick to .NET 1.1.
Cheers,
Greg
|
|
|
|
|
seikou wrote: Thanks, but the point is I can not tell the types beforehand, so I'd like to make it work for any type that has the appropriate methods, operators, etc.
That sounds like a job for an interface. If you specify an interface containing the methods and make the classes implement the interface, you can handle any object from those classes using the interface as data type, regardless of which actual data type they are.
---
b { font-weight: normal; }
|
|
|
|
|
I agree, this is a good solution.
If you need some sample code, feel free to ask.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi everyone,
I have made a c# application (from the article: Global System Hooks in .NET
By Michael Kennedy link) that installs a systemwide keyboard hook. This application emulate mouse clicks when specified key pressed.
It's work fine, only a little problem with it:
When keypess occures, my app hooks it, and Windows hoo too.
How can I told windows not to do that?
Example:
I set the 0 key to do left mouse click, when I press 0 in a textbox or in TotalCommander the click occures, and a 0 character appears in the textbox too
Hope somebody can help me :->
PS:
Sorry about my english
|
|
|
|
|
Hi,
I think you can download the Full Source of that article and make some changes on it. and recompile it.
In SystemHookCore.cpp at InternalKeyboardHookCallback function you should mark last line and add
return 1; instead of that line:
static LRESULT CALLBACK InternalKeyboardHookCallback(int code, WPARAM wparam, LPARAM lparam)
{
if (code < 0)
{
return CallNextHookEx(hookKeyboard, code, wparam, lparam);
}
if (UserKeyboardHookCallback != NULL && !keyboardFilter.IsFiltered((int)wparam))
{
UserKeyboardHookCallback(code, wparam, lparam);
}
return 1;
}
But I think it is a rapid solution. in addition you should add some mechanism in other class to check in application level that you want to take this action on this character or not.
Ahmadreza Atighechi
|
|
|
|
|
Thank's a lot!
It's works fine
Can you tell me, how can I modify the ManagedHook or HookCore project to tell them witch cases makes this return 1 trick, and witch not.
So how can I tell to the class from my C# app to do the return 1 action when my defined keys pressed, and otherwise do the normal action?
I think i shoud add somethink like this:
List<keys> l;
Than I add my specila keys to the list, and every time keypress occures I search the list for the actual key, when I find it, do the return 1...
Sorry for my stupid questions, but i not familiar with dll manipulation
I trí to modify SystemHookCore.cpp, and add a method, and a global witch set/store the keycodes, witch is exclude from system hooks. also modify the, managedhooks class, rebuild all, but when I start my app get error:
"Entry point(my new function name) was nt found on systemhook.dll"
Thank's for help!
-- modified at 10:29 Sunday 21st May, 2006
|
|
|
|
|
I am making a tray application with a custom ApplicationContext. Application exits OK when i close application manually. When i try to close application by doing Shutdown windows, windows aborts shutdown. I realize my problem is because application is not cleaning up.
What do i need to do so that my application will exit OK when a user chooses to Shutdown windows instead of closing manually? I am at a loss where to put clean up code.
|
|
|
|
|
Search this forum, I posted the answer to the same question only a week or 2 ago.
|
|
|
|
|
Please , can anyone here tell me where I can find significant information about Stacks and Queues in C#? I've been consulting many tutorials but nothing objective ...And I need it a lot now . Thanks
BiGjOe
Passez Ce Qu'il Passe
|
|
|
|
|
What sort of 'objective' information do you want ? Do you want to know about existing container classes, how to write your own, or just the nature of those container types ( regardless of language ) ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
If I have to decide , I could say the third , but really , I need general information about .
Thanks
BiGjOe
Passez Ce Qu'il Passe
|
|
|
|
|
OK. Google would have tons of info, what do you mean by 'objective' ?
Get the coins out of your pocket. Start putting them in a pile on your desk. This is a stack. When you take items off, the last item to go on is the first to go off.
When you go to the cinema, if it's busy, you need to stand in line to buy a ticket. This is a queue - the first person in the queue gets to leave the queue first.
That's all there is to how these two containers work. What other information were you looking for ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Well , that's what I know , and anything more . I've ever worked with stacks or queues , so , I think there's anything more . That's why the question .
I mean , arrays are too very simple , but I can read chapters about
BiGjOe
Passez Ce Qu'il Passe
|
|
|
|
|
I'm sorry, I don't understand the question at all. A stack or queue is probably implimented as a list, but you can think of it as an array which limits which items you can access at any time. There is tons of info around on container types, I have an O'Reilly book called Algorithms in C ( or something like that ) which is great for learning about this stuff.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Try this link: An Extensive Examination of Data Structures (including stacks and queues)
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/datastructures_guide.asp
Osama E. Adly
|
|
|
|
|