C# - OxyPlot how to add plot to windows form - c#

Trying out OxyPlot, installed and referenced packages. Copying and pasting the example from here http://docs.oxyplot.org/en/latest/getting-started/hello-windows-forms.html but it doesn't recognize plot1 from the last line. I am guessing because the control isn't added to the form. How do I add it? I don't see it in the toolbox, and I tried adding the control to the toolbox and can't find it anywhere. Thanks.

You may add the Plot Control Manually by appending these lines in the Form designer under the initialize component method.
private void InitializeComponent()
{
this.plot1 = new OxyPlot.WindowsForms.PlotView();
this.SuspendLayout();
//
// plot1
//
this.plot1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.plot1.Location = new System.Drawing.Point(0, 0);
this.plot1.Name = "plot1";
this.plot1.PanCursor = System.Windows.Forms.Cursors.Hand;
this.plot1.Size = new System.Drawing.Size(500,500);
this.plot1.TabIndex = 0;
this.plot1.Text = "plot1";
this.plot1.ZoomHorizontalCursor = System.Windows.Forms.Cursors.SizeWE;
this.plot1.ZoomRectangleCursor = System.Windows.Forms.Cursors.SizeNWSE;
this.plot1.ZoomVerticalCursor = System.Windows.Forms.Cursors.SizeNS;
this.Controls.Add(this.plot1);
//
// other comtrols
//
}
private OxyPlot.WindowsForms.PlotView plot1;

You said "I tried adding the control to the toolbox and can't find it anywhere.". It may not have found your installation of Oxyplot.WindowsForms. While in your visual studio project, after you right click on the Toolbox area, click on '.Net Framework Components' and then click 'Browse' and locate the "OxyPlot.WindowsForms.dll". If you installed it into your project it should be in one of the packages subfolders like packages\\lib folder.

I just had this very issue myself. I tried adding the Reference (right click References in the Solution Explorer, then browse for the "OxyPlot.dll" and "OxyPlot.WindowsForms.dll" files.) At first it didn't work; kept getting an error.
I noticed there were two versions of the "Oxyplot.dll; a net40 and a net45. I was originally using the net45 version. I copied the net40 version to the same place as the "OxyPlot.WindowsForms.dll", added the Reference, went to the toolbox, added a new tab, then added the reference to the tab (right click tab -> Choose Items, then search for Oxyplot).
I now have Pointer and PlotView in the toolbox. I'm using VS2017 Community with a Forms app. The manual version above worked for me too.

Related

Why does adding a new code file to a C# program cause a form (menu) to be created?

I'm a Java programmer new to C#. I've created a C# WinForms program. It is intended to have a single form. All well and good.
That is, until I create a new Code File, and add it to the project. Then in Solution Explorer, whenever I select the new code file, it brings up a blank form. I had no intention of creating a new form - just a new code file. Can I eliminate this new form? It creates a new form for every code file I add, and that was not my intention. I merely want to add code files without Visual Studio creating a new form every time I do.
Please help. Thanks.
When you select your project -> right click -> new element - You need to choose "C# Class" not "C# Windows Form".
If you right click the form in the inspector you can delete the form or view it's code.
Edit:
On the right panel where you have your solution - do not select the solution but the element below it. When you have it selected, right click and choose 'Add -> New Element'. Then from the list choose "Class". Then you double click the class in the right side panel and that should bring your code file up not the form.
Edit2:
using System;
namespace CDP
{
public class Class1
{
public PassFail PassFailVerify()
{
return PassFail.Pass;
}
}
}

Creating sub context menu items in the registry

I need my app to create right-click context menu items (and sub-menu items). I'm not concerned with the code - but I don't know how to make sub-menu items in the registry. It's not as logical as one would expect.
I've searched countless times already and have officially given up searching for now.
I know that we can create a context menu item using regedit.exe by going to the shell key and adding a new one but how do I create sub menu items like 7zip for example?
Take a look at this Code-Project article: Add a context menu to the Windows Explorer. It seems to be very easy by using the Registry class provided by the .net framework.
Some more advanced/better solution seems to be using some library such as: SharpShell
EDIT
Please take a look at: .NET Shell Extensions - Adding submenus to Shell .
Ths part should solve your problem:
// <summary>
// Creates the context menu when the selected item is a folder.
// </summary>
protected void MenuDirectory()
{
ToolStripMenuItem MainMenu;
MainMenu = new ToolStripMenuItem
{
Text = "MenuDirectory",
Image = Properties.Resources.Folder_icon
};
ToolStripMenuItem SubMenu1;
SubMenu1 = new ToolStripMenuItem
{
Text = "DirSubMenu1",
Image = Properties.Resources.Folder_icon
};
var SubMenu2 = new ToolStripMenuItem
{
Text = "DirSubMenu2",
Image = Properties.Resources.Folder_icon
};
SubMenu2.DropDownItems.Clear();
SubMenu2.Click += (sender, args) => ShowItemName();
var SubSubMenu1 = new ToolStripMenuItem
{
Text = "DirSubSubMenu1",
Image = Properties.Resources.Folder_icon
};
SubSubMenu1.Click += (sender, args) => ShowItemName();
// Let's attach the submenus to the main menu
SubMenu1.DropDownItems.Add(SubSubMenu1);
MainMenu.DropDownItems.Add(SubMenu1);
MainMenu.DropDownItems.Add(SubMenu2);
menu.Items.Clear();
menu.Items.Add(MainMenu);
}
You have to create a command folder for example Archive, with two commands: A and B.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell\Archive]
"MUIVerb"="Archive"
"SubCommands"="Windows.A;Windows.B"
The * in key means this menu shows up at right click on any file. If you want it only at the *.7z files, use HKEY_CLASSES_ROOT\.7z\shell\Archive. The value of MUIVerb will be the name of menu item. If you named the MUIVerb to 7-Zip, the right click menu will contains two 7-Zip items.
Then create the commands there:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Windows.A]
"MUIVerb"="Command name of A"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Windows.A\command]
#="notepad.exe \"%1\""
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Windows.B]
"MUIVerb"="Command name of B"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Windows.B\command]
#="notepad.exe \"%1\""
In this example, you get an Archive menuitem, with cascaded two command, whats open the current file with notepad. It works with Windows 7 and newer.

Odd visual behavior from ToolStripMenuItem

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.

reportviewer not shown on form designer (c# winform)

I user reportviewer for my winform app!!!
now when i select reportviewer control from toolbox and add that to page controler, any thing not shown on form designer , but bottom of page the name of reportviewer will be seen!!!
i really confused for this problem !!!
this problem appeared when i make backup from my project !!! and before that i did't have any problem with report viewer!
(i set location and size of reportviewer manually but ...)
this.reportViewer1.Location = new System.Drawing.Point(0, 0);
this.reportViewer1.Name = "ReportViewer";
this.reportViewer1.Size = new System.Drawing.Size(396, 246);
this.reportViewer1.TabIndex = 0;
this.reportViewer1.Visible = true;
I found a workaround
this line Manual added
this.Controls.Add(this.reportViewer1);
on method
InitializeComponent
Why when
Drag-drop control on the Windows Forms
Not added automatic
P.s
Sorry for my english
I had the same problem as you and I solved it by updating the dll Windows.ReportViewer.Winform (version 10.0) to (version 11.0) with Nuget.
For those that didn't have the ReportViewer control in the Toolbox so they followed the instructions and added the control manually -- if you don't see the ReportViewer control after dragging the (now available) ReportViewer control, then right click on References in your project structure, then browse to the exact same location from where you took the ....WinForm.dll or WebForm.dll and this time choose ...Designer.dll.
Rebuild your project and try dragging again. This time the control should be visible on the form.
install version 11.0.3452.
It's working for me. enter image description here.
How I solved the same issue. Deleted the reference Windows.ReportViewer.Winform and Microsoft.ReportViewer.Common and dragged report viewer control on the form and added this line this.Controls.Add(this.reportViewer1); in private void InitializeComponent()
Install the nuget package:-
Microsoft.ReportingServices.ReportViewerControl.Winforms
It will solve the issue

How to add ToolStripSplitButton to Visual Studio Toolbox?

I am using Visual Studio 2010, and I have come across a need to use the ToolStripSplitButton button. I figured out from the reference material that ToolStripSplitButton is a form found under the System.Windows.Forms.
When I attempt to add this to my toolbox to try to use, I am unable to find ToolStripSplitButton, does anybody know how I can add this to my Visual Studio 2010 so I can use it? I don't care if it's not in the toolbox, I just want to make sure the assembly reference is present so I can actually use it.
ToolStripSplitButton can be used only as ToolStripItem of a ToolStrip (contained in ToolStrip.Items). It's designed so that you can't use it as a normal control. It doesn't have a Parent property, and I guess it also doesn't have a Handle property. The inheritance tree is:
ToolStripSplitButton
-> ToolStripDropDownItem
-> ToolStripItem
-> Component
-> ...
Normally, you have to add some ToolStrip to host ToolStripSplitButton.
If you want to use code, here is a simple example:
ToolStrip toolStrip1 = new ToolStrip();
ToolStripSplitButton splitButton1 = new ToolStripSplitButton("Hi there"){Owner = toolStrip1};
//you can add items to ToolStripSplitButton via ToolStripSplitButton.DropDownItems
More info ToolStripSplitButton
It's inherited from and dependent on ToolStripDropDown so you can't use it as a stand-alone control.
You can use it as a child control for ToolStripDropDown.

Categories