I am having exactly the same problem.
I use a SplitContainer and and have placed a TreeView control inside. In the right side of the split container, one of five different Forms shall be loaded, depending on what's selected in the TreeView. Up to now, I unfortunately have not found a solution, but I'm new to C#, so this does not mean anything
"SubForms" even work in LabVIEW, so I would be very amazed, if C# would be unable to do the same...
Perhaps you could use the NativeWindow class, passing a CreateParams structure with its Parent property set to the Handle property of the right handle Panel. Then, display the form and use the SetParent PInvoke call to make it a child window of the parent
NativeWindow wnd = new NativeWindow(new CreateParams()
Parent = rightHandPanel.Handle,
Height = rightHandPanel.Height,
Width = rightHandPanel.Width,
X = Y = 0
Form display = formYouWantToDisplay;
display.Show(wnd); //This works because NativeWindow implements IWin32Window
This would require quite a bit of research to work properly I think. Are you sure you don't just want to have an MDI parent, and dock a panel containing a treeview to the left hand side?
For any one interest in this
Here I publish my solution
Object in Form1
tabControl1 (in the right panel of the splitContainer1)
The tabControl does not have any page on design.
The left panel I intent to put a treeView, but for this code, there is a button
button1 (in the left panel of the splitContainer1)
Becaus Microsoft does not provide the Tab control we all use in the IDE, that allow to close a tabpage with an X in the upper right corner, I have no alternative and just use a normal tabControl
Now, in order to destroy the tabpage when closing the form created on each page.
In Form2 I add a button, and the followin code.( this close the form and destroy the tab page.
To make your application run when Windows starts, put it into the Startup folder. I think there are registry keys you can add it to. To make the tray icon, use the NotifyIcon component, and simply show the form with the calendar upon the double click of the aforementioned component. You can actually find a calendar-like component in the .Net Framework - I think it's something like DateTimePicker. Inherit from that, link it to a collection of dates, and you have your calendar. To make the form display on the right hand side of the desktop, set the Dock property of the form to Right
I see. You could theoretically put some code in the Resize event handler to adjust the size and location of the form. Use these equations:
Form.X = Screen.Width - Form.Width
Form.Y = 0
Form.Height = Screen.Height
Form.Width can be anything you want it to be. This will look best if you set the BorderStyle to None
But i want to bound the calender application object added to Windows Desktop Object in such a way that it behave like icons on desktop. so that when all applications in Taskbar are minimized my application still will be visible on desktop
Basic thing i want is access to desktop and put my calender object into that.
Then what you may want is to create a gadget for the Sidebar. This will limit your options to Vista. Alternatively, you could look into shell integration (perhaps a knowledge of COM would help you here) or the ShowInTaskbar property of a form
You can save in one setting entry only one value. From what you are doing, you are trying to save 3 different locations to one setting entry(SavedSetting3) which is wrong. In each loop execution you are overwriting the last set value and hence, the value which is last written (button3 I guess) is the one which is saved. You will need to create 3 different setting's entry to save each of the buttons location.
Your problem lies with the File.Create method. It returns a FileStream instantiation. Until you close the FileStream, you cannot read the file without requesting different access to it. Try something like this
Stream bookStream = new FileStream("books.txt", FileMode.OpenOrCreate);
using(StreamReader booksReader = new StreamReader(bookStream))
//Do what you want with booksReader here, the using block will automatically close the streams to avoid memory leaks
The trick here is creating a new FileStream with FileMode.OpenOrCreate. If the file exists, it is opened; if it doesn't exist, it is created and then opened. If you want to check whether the file is empty (it's pointless reading from an empty file), check whether bookStream.Length is equal to zero. This will also tell you if the file is newly created because the newly created file will be empty