I've got a Drop Down Menu that is dynamically filled every time it opens, here is the logic that does it:
private void joysticksToolStripMenuItem_DropDownOpening(object sender, EventArgs e)
{
_joysticks = _joystickWrapper.FindDevices(DeviceType.Joystick);
joysticksToolStripMenuItem.DropDownItems.Clear();
foreach (var di in _joysticks)
{
var item = new ToolStripMenuItem(di.ProductName);
item.Checked = di.InstanceGuid == _joystickWrapper.CurrentDeviceInfo.InstanceGuid;
joysticksToolStripMenuItem.DropDownItems.Add(item);
}
}
When I run the application this is what I see:
The check is in the wrong location and the blue area is too wide.
Any ideas on where to look to fix this? The entire menu is all System.Windows.Forms, no custom visual code in the entire application.
I tried on my current machine (Windows 10 Build 9926) and on my dev server (Server 2012R2) with the same results. I've also compiled this to the NET Framework 4.5 and 4.5.1
EDIT
For those interested, here is the git repo for this project:
https://github.com/adam8797/RovControl
I came across this exact same issue and was finally able to resolve it by setting the ImageScalingSize property of the MenuStrip to 16,16 (it had somehow been set to 32,32, possibly due to my editing of the form on a high DPI machine)
I see you adding items in Menu while its opening. Seems like the selected area and its width is already defined and its not reacting to the new data you inserted. What about trying to manually define width of Menu Item and see if that helps.
Related
Still setting my first steps in WPF, this time I'm dealing with this "simple" situation:
dt_Proposal.Rows[0].ItemArray[i] = highest_val + min_val;
This piece of code has been run for every value of i (also for value 2), so I expect to see something on the place of the red rounded rectangle:
However I don't see any value there.
I decided to pauze my application (Visual Studio "Debug" menu, "Break All" menu item), and then I thought of having a look at the controls of my form, but how?
Visual Studio's "Locals" window contains this, which is mentioned being a <Application_Name>.MainWindow, but I can't look deeper.
When adding this to the "Watchlist", this seems not even to be accessible.
So this becomes a very general question: I am working on the GUI of a WPF application, and I would like to see the properties/fields of the controls/GUI components of my main form, and I would like to do this while my application is waiting on any kind of user input (typical "wait state" for a GUI application).
How can I do that?
In WPF you can see Visual Tree (even without pausing the app at all!), you enter this like shown in below picture:
By the way, value hello world was set programatically:
private void Button_Click(object sender, RoutedEventArgs e)
{
txtInfo.Text = "hello world";
}
Once in Visual Tree, you can right click control and show its properties:
And there you can see values of properties set:
Hi I am having a very strange problem. I have a form with multiple tooltips that appear when the mouse is over a specific control. So far I was developing the form on a Windows 7 machine and everything were going fine. Tonight I tested my executable on my other Windows 7 machine (same version and service pack) but none of the tooltips are working.
Does anybody have an idea what might be the problem? Bellow I am giving the code for one such Tooltip
ToolTip UrlNameInputBallonTip = new ToolTip();
private void CheckForUrl()
{
UrlNameInputBallonTip.IsBalloon = true;
if (IsValidHttpUri(UrlNameInput.Text) == false && IsValidHttpsUri(UrlNameInput.Text) == false)
{
UrlNameInputBallonTip.SetToolTip(UrlNameInput, "This is not a valid url!\r\nex. \"http://domain\"");
UrlNameInputBallonTip.Show("This is not a valid url!\r\nex. \"http://domain\"", UrlNameInput, UrlNameInput.Width / 2, UrlNameInput.Height, 5000);
}
else
{
UrlNameInputBallonTip.Hide(this);
}
}
Hi I was able to find the cause of the problem and I am reporting this for future reference. On the suspected machine the option to display balloon tips (arrow pointing to the control) was disabled. I am not sure why, perhaps some other app disable it at some point, but after enabling it through registry ti works fine now. Thanks for the help!
I'm trying to drag one or more files from my application to an outlook mail-message.
If I drag to my desktop the files are copied to the desktop as expected, but when dragging into a new outlook 2013 mail message, nothing happens... Only when I drag explicitly to the 'attachments textbox' do they appear, this is not helpful because the attachment-textbox isn't shown by default.
I don't understand why when I drag file(s) from my desktop to the mail I can just drop them and the attachment-text automatically appears showing the files but when I drag from my app it's not working..., here's my code :
'
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
var _files = new string[] { #"E:\Temp\OR_rtftemplates.xml", #"E:\Temp\Tail.Web_Trace.cmd" };
var fileDragData = new DataObject(DataFormats.FileDrop, _files);
(sender as Form).DoDragDrop(fileDragData, DragDropEffects.All);
Console.WriteLine("{0} - button1_MouseDown", DateTime.Now.TimeOfDay);
}
'
I've also added the files to the DataObject by using the 'SetFileDropList' method but that makes no difference.
The must be some magic property I have to set to get this working right with an outlook-message.
I hope someone can shed some light on this.
thanks,
Jurjen.
I just tested some other stuff on a machine running .NET 4.0 (app was compiled in .NET 4.5), after changing .NET target to 4.0 and recompiling it does work, dragging files into a new outlook message, very strange, might be a problem when migrating to .NET 4.5 later... but for now it works...
Environment
Windows XP x32 Visual Studio 2005 Standard Edition
Honeywell Dolphin 9500 running Windows Mobile 2003 (Pocket PC 2003) With built in Barcode scanner and B&W camera Using their SDK located here.
.NET Compact Framework 1.0 SP3 and .NET Framework 1.1
Using VC#
Goal
I have a ListView control with CheckBoxes = true and View = Details on a form but I don't want the check boxes to be "checkable" by the user. I am using it for a status display of record completion. I do, however, want to use the event handler function to check the box via code (i.e. on record completion: lvMeters_ItemCheck(null, null);).
Problem
I have disabled checking the box itself (I think, the touch screen isn't real precise on this device). However, when selecting a row (I have FullRowSelect = true), the control often checks the checkbox and the event handler doesn't seem to be getting called.
Things I have Tried
I tried to basically undo the action in the event handler:
private void lvMeters_ItemCheck(object sender, ItemCheckEventArgs e)
{
if (sender is ListView)
{
if (e.CurrentValue == CheckState.Checked)
lvMeters.Items[e.Index].Checked = true;
else
lvMeters.Items[e.Index].Checked = false;
}
else if (e.CurrentValue == CheckState.Checked)
lvMeters.Items[e.Index].Checked = false;
else
lvMeters.Items[e.Index].Checked = true;
}
The problem is the above handler doesn't get called on a listview select, nor does the SelectedItemChanged event handler call this event handler but it's still checking the box on select. It does get called when checking the box itself.
Need additional information?
Ask away and I'll do my best!
I'm A Novice
So please feel free to tell me I am doing this completely wrong and should do the entire thing differently.
I'm not familiar with the limits of the ListView on the compact framework, but on the standard framework, you can use the TreeNode.StateImageIndex property. The unchecked/checked states are in fact using small images embedded in the standard winforms code (If I remember correctly, they are index 1 and 2). So, for example, if you do this:
private void lvMeters_ItemCheck(object sender, ItemCheckEventArgs e)
{
e.Item.StateImageIndex = 3;
}
It will change the small icon and set it to nothing. You can also use the ListView ImageList.
Sigh...I somehow managed to remove the event handler from the control when muddling with the designer. I checked at some point and it was still there but at that point I actually did have a logic/code problem.
Thanks for your answers :/
I plan to add functionalities to TextBox with the following:
public class TextBoxExt : TextBox
{
protected override void OnKeyPress(KeyPressEventArgs e)
{
base.OnKeyPress(e);
}
}
The question is how can we use this TextBoxExt? Is there anyway to get this class onto the ToolBox so that we can just drag and drop it onto the form? If not, what is the best way to use the TextBoxExt?
Build you project with TextBoxExt, make sure it compiles ok.
With the form that you want TextBoxExt on, open the toolbox, right click and select "choose items"
Browse to you .exe or dll that you compiled in 1)
make sure that TextBoxExt has a tick next to it, press ok
TextBoxExt should appear in the toolbox, drag it onto your form
(There is another way of doing this, opening the designer file and renaming the instances of TextBox to TextBoxExt but manual editing of designer files can be considered hazardous by some)
I know this is super old question, but maybe still useful for someone else that has same problem like me - as it's still on the top Google :)
You might interest to use ToolboxItemAttribute (http://msdn.microsoft.com/en-us/library/system.componentmodel.toolboxitemattribute(v=vs.110).aspx).
I did this at my end to resolve the problem.
[ToolboxItem(true)]
public class PanelTitle : LabelControl {
// Whatever code to override LabelControl here...
}
Rebuild the solution and the extended control should be shown in the toolbox.
Any custom control in your project should show up in the Toolbox automatically. I have found that sometimes the controls won't show until you close a re-open Visual Studio. I assume the issue has something to do with caching of the contents of the Toolbox.
You need to add a constructor to your derived class.
public class TextBoxExt : TextBox
{
public TextBoxExt()
{
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
base.OnKeyPress(e);
}
}
Your control should appear in the toolbox for your solution automatically. To have it appear for other projects, you have to do Choose Toolbox items, as others have said.
If you want to provide special design-time functionality, then you will also need to provide some additional designer related attributes and probably your own class derived from ControlDesigner.
I fell into this trap just a couple of hours ago.
I've got a .NET 2.0 Windows Application project with some custom UserControls; it worked fine.
So I decided to order my files in subfolders, to make my project a little bit cleaner.
After that, Visual Studio 2010 designer stopped loading my forms, and ToolBox won't show my controls anymore.
I freaked out, moving back source files in project root, resetting ToolBox, but nothing seemed to work.
After that, I remembered I used ReSharper "Remove Unused References", so I tried to put back unused reference, in particular System.Data: problem solved! :O
I can't say you why, but this worked for me.
Hope my experience can help someone else. :)
Bye,
Nando
I created an empty constructor for my custom implementation of UltraGridBagLayoutPanel. Although david.healed is right it isn't necessary, it is quite useful to put a breakpoint in to check that when the form initialises it is using your class to implement your custom control.
It would have been a lot easier to edit the designer file, but I tried it and changed both the field type for the control and also changed the assignment of the field to a new instance of my custom control.
private Infragistics.Win.Misc.UltraGridBagLayoutPanel ultraGridBagLayoutPanel1;
this.ultraGridBagLayoutPanel1 = new Infragistics.Win.Misc.UltraGridBagLayoutPanel();
to
private Athia.Reports.ultraGridBagLayoutPanel1 ultraGridBagLayoutPanel1;
this.ultraGridBagLayoutPanel1 = new Athia.Reports.ultraGridBagLayoutPanel1();
Doing this destroys Visual Studio every time, and to fix it requires using a text editor to put it back again. Therefore unless anyone can describe what is wrong with my implementation of this approach, perhaps calling the class the same as the control name isn't a great idea, I think the only safe and reliable way to achieve this is as Calanus describes in steps 1 to 5 or as an small deviation from that as Rob Windsor rightly points out restarting VS will bring the control into the Toolbox automatically. Unfortunately for me I then have to change all of the child controls over from the original class to my customised class :-(.
Within the same Solution this should work automatically. However, I have found that if the Target Framework aren't matching the Toolbox does not populate. ( I'm assuming really Reference needs to be of version same or lower than target of Reference. ) ( I did get a warning about non-matching Frameworks )
By making these the same Target Framework, Recompile, Restart VS. the control populated correctly. ( I also added the ToolboxItem(true) Attribute)