|
Hey Ian,
Once again, thanks for the response. I don't seem to have an issue aligning to the sides. I just can't calculate the proper "X" value while centering the desired text. This is completely beyond me. I really appreciate your help. If you have any other suggestions, I would like to hear them.
Thanks again
PHD
|
|
|
|
|
I'm writing a rather large data access application (CLR 2.0, rich-client), and I've started adding some security routines. Simple flags to prevent certain users from editing certain items.
Basically, I have a number of record editing dialogs (Well, I have one so far, but there will be many), and I'm trying to find a way to make them double as read-only viewers for users who aren't allowed to make changes.
The idea is to prevent the user from interacting with any controls that are "locked" without damaging the appearance.
* I don't want to subclass the windows forms controls (I'm using aspects to add custom behavior via event hooking when needed) as the program uses a LOT of them, and I don't want to slow down GUI updates and layout logic with extra layers of inheritance, especially when only a fraction of the controls will use this particular feature.
* I don't want to just set the Enabled property, as this grays out the control, making it difficult to read and therefore useless as a viewer. Textboxes have their ReadOnly property, but this doesn't help for dropdowns, checkboxes, etc.
* Data integrity is not an issue here, as the changes are all funneled through a secure update routine. This is exclusively a display issue. I don't want the user to be able to change control values if those changes can't be saved anyway.
I can hook the keydown events to kill any keyboard actions on them, and set a dummy context menu to prevent right-click copy/pasting, so textboxes are easily handled. It's the other controls (Comboboxes, checkboxes, radiobuttons) that are the real issue.
Since I can restrict any keyboard entry, an ideal solution would be a way to just intercept any mouse activity before it reaches the controls. On a simpler scale, I could hover a transparent form to actually shield them, but that would be horribly inefficient in this case.
I've tried hooking the GotFocus and automatically moving the focus to another control, but this isn't sufficient, since the initial mouse click goes through before the focus is moved, and that's enough to click a button or hit the dropdown button on a combobox. Looks amateurish if the dropdown triggers, then kicks you out.
Worst case, I'll just make separate editors and viewers, but I'm trying to avoid this if possible. This app will see a lot of maintenance, by me and any future teammates, and I want that to be as painless as possible.
Any ideas?
|
|
|
|
|
First let me say excellent post. And Second, I thought of a simple solution to the combobox problem. When you are in display mode why not use textboxes instead? The lack of the dropdown graphic would make it clear that it is read only and you have already figured out how to handle textboxes. I realize this won't be nearly as satisfying as the high-end solutions you're coding, but I believe it would be effective. Also if you get all of this figured out it would make a killer article on the site, if you get a chance. Best of luck.
topcoderjax - Remember, Google is your friend.
|
|
|
|
|
Hot-swapping the control would require some redesigning, but might be an option if I can't figure this out. Right now, I have the locking routine in a utility library (Separate assembly):
public static void LockEditing(Form frm, params Control[] exceptions)
So the editor form, after running a security check, calls it using:
<CompanyName>.Util.ControlOperations.LockEditing(this, btnCancel);
btnCancel.Text = "Close";
Nice and clean, but limits me to public interfaces, so the form itself would have to do the swapping, instead of the centralized code.
|
|
|
|
|
Bingo. Switching controls would have been too intrusive to the design, but you gave me the winning idea. It's a little odd, but it works like a charm...
First, the lock routine goes through the control tree of the form, and finds the highest-level controls possible without including the exceptions, and locks those only. Fun little algorithm, but not the point, so onward...
I knew I couldn't override the WndProc, and totally eat mouse messages, without subclassing, right? Well, that doesn't stop me from adding an extra container.
Form
|
|-Panel1
\-Something
\-Panel2
|-Something
\-CancelButton
Becomes...
Form
|
|-LockPanel
| \-Panel1
| \-Something
\-Panel2
|-LockPanel
| \-Something
\-CancelButton
The LockPanel instances are empty panels that basically swallow the member control. They set their location/size/dock to the control, set their backcolor to the parent, insert themselves in place of the control, and Dock.Fill the control into themselves. Basically, it adds a controllable layer without affecting the form's logic.
Why, though?
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x0021)
m.Result = new IntPtr(4);
else
base.WndProc(ref m);
}
This, along with a KeyDown hook that sets Handled and SuppressKeyPress to true, makes the controls react to hover-type events (They light up, highlight borders, etc), but not to clicks of any sort. As for the keyboard, you can <tab> into them, but can't actually affect the contents.
|
|
|
|
|
Hello,
Very Nice idea (got my "5")
Just couse I'm currious (and had the same problem once).
Do you have TextBoxes in your panel aswell?
If yes, do they get focused and show the carret?
All the best,
Martin
|
|
|
|
|
They do get focused, but not by mouse clicks. You can <TAB> to them, but can't actually modify them.
|
|
|
|
|
O.K.
I had the same problem (and I didn't whanted to se the carret inside the textbox), so as a workaround I handled (overrided) the OnFocus and reseted the focus on an other (hidden) Control.
All the best,
Martin
|
|
|
|
|
Oh and another thought, how about disabling the controls and hooking the paint event to display them as though they were enabled.
topcoderjax - Remember, Google is your friend.
|
|
|
|
|
Ian Shlasko wrote: * I don't want to just set the Enabled property, as this grays out the control, making it difficult to read and therefore useless as a viewer. Textboxes have their ReadOnly property, but this doesn't help for dropdowns, checkboxes, etc.
One other option would be to manually change the color from gray to black when you disable it. IIRC if you do this though and subsequently want the control both disabled and grayed you'll have to manually set it to gray.
--
You have to explain to them [VB coders] what you mean by "typed". their first response is likely to be something like, "Of course my code is typed. Do you think i magically project it onto the screen with the power of my mind?" --- John Simmons / outlaw programmer
|
|
|
|
|
Hello I have one executable file "prog.txt" made in the folder "glpsol" created with this command line glpsol -m tsp.mod -o prog.txt in command prompt I want to know how can I do this from c# not from Command prompt(to create prog.txt in folder glpsol with that command line glpsol -m tsp.mod -o prog.txt)...thanks
lavi
|
|
|
|
|
System.Diagnostics.Process.Start(@"glpsol -m tsp.mod -o prog.txt");
Standards are great! Everybody should have one!
|
|
|
|
|
Use System.diagnostics name space.
"In quiet and silence, the truth is made clear."
|
|
|
|
|
you can use post-build and pre-build events of your project to do this.
right click on your project go to properties and then to build events
then chose whatever is suitable to u. (post-build or pre-build)
|
|
|
|
|
|
Hi friends..
I have designed one windows application with one button control on it..I want to open one new Internet browser window with some url on click of that button..
regards,
Rahul
|
|
|
|
|
To open in IE System.Diagnostics.Process.Start("iexplore","http://www.codeproject.com/");
To open in the default browser use System.Diagnostics.Process.Start("http://www.codeproject.com/");
Last modified: 59mins after originally posted --
|
|
|
|
|
|
We need to provided the full path of the IEXPLORER.EXE as 1st parameter.
like
System.Diagnostics.Process.Start(@"C:\Program Files\Internet Explorer\IEXPLORE.EXE", @"http://www.yahoo.com");
Manoj
Never Gives up
|
|
|
|
|
Why do you need to provide it? Just using System.Diagnostics.Process.Start("http://www.codeproject.com/"); will open it in the default browser.
|
|
|
|
|
Does anyone know where this is a list of the solution explorer icons and their meaning? I tried a search on google, but the search terms return a mess of useless links.
Thanks.
C26
|
|
|
|
|
Just have a look in "VisualStudio2005\Common7\VS2005ImageLibrary\VS2005ImageLibrary\bitmaps\outline\24bitcolor"
(might have to uncompress VS2005ImageLibrary.zip)
dir vsproject* , will give you :
VSProject_asa.bmp
VSProject_asp.bmp
VSProject_bmp.bmp
VSProject_brokenlink.bmp
VSProject_brokenreference.bmp
VSProject_cab.bmp
VSProject_component.bmp
VSProject_control.bmp
VSProject_CSCodefile.bmp
VSProject_css.bmp
VSProject_database.bmp
VSProject_dynamicdiscovery.bmp
VSProject_form.bmp
VSProject_generatedfile.bmp
VSProject_genericfile.bmp
VSProject_genericproject_small.bmp
VSProject_hiddenfile.bmp
VSProject_html.bmp
VSProject_imagefile.bmp
VSProject_reference.bmp
VSProject_report.bmp
VSProject_resourcefile.bmp
VSProject_schema.bmp
VSProject_script.bmp
VSProject_VBCodefile.bmp
VSProject_webcomponent.bmp
VSProject_webcontrol.bmp
VSProject_webform.bmp
VSProject_xml.bmp
VSProject_xsl.bmp
Is that what your are looking for ?
thod_Friend.bmp
VSObject_Method_Private.bmp
VSObject_Method_Protected.bmp
VSObject_Method_Sealed.bmp
VSObject_Method_Shortcut.bmp
VSObject_Module.bmp
VSObject_Module_Friend.bmp
VSObject_Module_Private.bmp
VSObject_Module_Protected.bmp
VSObject_Module_Sealed.bmp
VSObject_Module_Shortcut.bmp
VSObject_Namespace.bmp
VSObject_NamespacePrivate.bmp
VSObject_NamespaceProtected.bmp
VSObject_Namespace_Friend.bmp
VSObject_Namespace_Sealed.bmp
VSObject_Namespace_Shortcut.bmp
VSObject_Object.bmp
VSObject_ObjectShortcut.bmp
VSObject_Object_Friend.bmp
VSObject_Object_Private.bmp
VSObject_Object_Protected.bmp
VSObject_Object_Sealed.bmp
VSObject_Operator.bmp
VSObject_Operator_Friend.bmp
VSObject_Operator_Private.bmp
VSObject_Operator_Protected.bmp
VSObject_Operator_Sealed.bmp
VSObject_Operator_Shortcut.bmp
VSObject_Properties.bmp
VSObject_Properties_Friend.bmp
VSObject_Properties_Private.bmp
VSObject_Properties_Protected.bmp
VSObject_Properties_Sealed.bmp
VSObject_Properties_Shortcut.bmp
VSObject_Structure.bmp
VSObject_Structure_Friend.bmp
VSObject_Structure_Private.bmp
VSObject_Structure_Protected.bmp
VSObject_Structure_Sealed.bmp
VSObject_Structure_Shortcut.bmp
VSObject_Template.bmp
VSObject_Template_Friend.bmp
VSObject_Template_Private.bmp
VSObject_Template_Protected.bmp
VSObject_Template_Sealed.bmp
VSObject_Template_Shortcut.bmp
VSObject_Type.bmp
VSObject_TypeDef.bmp
VSObject_TypeDefShortcut.bmp
VSObject_TypeDef_Friend.bmp
VSObject_TypeDef_Private.bmp
VSObject_TypeDef_Protected.bmp
VSObject_TypeDef_Sealed.bmp
VSObject_Type_Friend.bmp
VSObject_Type_Private.bmp
VSObject_Type_Protected.bmp
VSObject_Type_Sealed.bmp
VSObject_Type_Shortcut.bmp
VSObject_Union.bmp
VSObject_UnionPrivate.bmp
VSObject_Union_Friend.bmp
VSObject_Union_Protected.bmp
VSObject_Union_Sealed.bmp
VSObject_Union_Shortcut.bmp
VSObject_ValueType.bmp
VSObject_ValueTypePrivate.bmp
VSObject_ValueType_Friend.bmp
VSObject_ValueType_Protected.bmp
VSObject_ValueType_Sealed.bmp
VSObject_ValueType_Shortcut.bmp
Is that what your are looking for ?
|
|
|
|
|
Hi
Can someone tell me how to return an array from a function???
Regards
sAqIb
"Our scientific power has outrun our spiritual power. We have guided missiles and misguided men."
Dr. Martin Luther King Jr.
|
|
|
|
|
object[] MyFunction()
{
}
|
|
|
|
|
public string[] myfunction()
{
string[] myarray = {"test","test","Test"};
return myarray;
}
topcoderjax - Remember, Google is your friend.
|
|
|
|
|