How can I ensure that a UserControl that has been docked to an MDIForm doesn't get docked a 2nd time? That is, I need a control to only be visible once. I tried making it a singleton class, but calling the DockControl of the RadDock still added a new visual element, though one was an empty shell.
I tried to find a list of controls or some other addressable way but failed.
Thanks,
VSmirk
I tried to find a list of controls or some other addressable way but failed.
Thanks,
VSmirk
5 Answers, 1 is accepted
0
Richard Slade
Top achievements
Rank 2
answered on 12 Feb 2011, 01:21 PM
Hi VSmirk,
Have a look at my replies in this forum post which may help you. If that's not what you mean, then let me know a bit more about what you have and I'll do my best to help.
Thanks
Richard
Have a look at my replies in this forum post which may help you. If that's not what you mean, then let me know a bit more about what you have and I'll do my best to help.
Thanks
Richard
0
Richard Slade
Top achievements
Rank 2
answered on 14 Feb 2011, 11:33 AM
Hello,
Did this help? If so please remember to mark as answer. If you need further assistance, let me know
thanks
Richard
Did this help? If so please remember to mark as answer. If you need further assistance, let me know
thanks
Richard
0
Hi Vania,
I hope this was helpful.
Kind regards,
Julian Benkov
the Telerik team
Like Richard said, you can find and use the solution from the given forum thread. In addition, you can use following code snippet for your scenario:
public
partial
class
DockForm : Form
{
public
DockForm()
{
InitializeComponent();
}
private
void
radButton1_Click(
object
sender, EventArgs e)
{
UserControl myControl =
new
UserControl();
DockControl(myControl);
}
private
void
DockControl(UserControl myControl)
{
foreach
(DockWindow dockwindow
in
this
.radDock1.DockWindows)
{
if
(dockwindow.Controls.Count > 0 && dockwindow.Controls[0] == myControl)
{
return
;
}
}
this
.radDock1.DockControl(myControl, DockPosition.Fill);
}
}
I hope this was helpful.
Kind regards,
Julian Benkov
the Telerik team
0
scottw
Top achievements
Rank 1
answered on 15 Feb 2011, 03:14 PM
Julian,
Thank you for your post. Your solution presumes the control is a singleton, and does not work otherwise as the caller of the function instantiates an entirely new instance. But I think I can make it work.
While I can make the UC a singleton and avoid the creation of the control the 2nd time, I am not able to delete the static instance of the user control as I cannot find a reliable event in which to do this.
I tried a variation on your code and tested the name rather than the instance, but it appears there is a different problem. Closing the control does not appear to unload it from the dock window's controls.
Thank you!
Thank you for your post. Your solution presumes the control is a singleton, and does not work otherwise as the caller of the function instantiates an entirely new instance. But I think I can make it work.
While I can make the UC a singleton and avoid the creation of the control the 2nd time, I am not able to delete the static instance of the user control as I cannot find a reliable event in which to do this.
I tried a variation on your code and tested the name rather than the instance, but it appears there is a different problem. Closing the control does not appear to unload it from the dock window's controls.
private void ShowLibraryMaintenance()
{
ucLibraryInfoBar _ucLibraryInfoBar = new ucLibraryInfoBar(_logic);
_ucLibraryInfoBar.Name = "LibraryInfoBar";
ShowInfoBar(_ucLibraryInfoBar);
FrmLibraryMaintenance _frmLibraryMaintenance = FrmLibraryMaintenance.Instance(_logic, OnSelectedSongChanged);
_frmLibraryMaintenance.MdiParent = this;
_frmLibraryMaintenance.Show();
//sets visibility of menu items based on access control
SetMenuItems();
}
private void ShowInfoBar(UserControl libraryInfoBar)
{
foreach (DockWindow dockwindow in this.rdMainDock.DockWindows)
{
if (dockwindow.Controls.Count > 0 && dockwindow.Controls[0].Name == "LibraryInfoBar")
{
return;
}
}
HostWindow _libHost = rdMainDock.DockControl(libraryInfoBar, DockPosition.Left);
_libHost.DockTo(_libHost, DockPosition.Fill);
((ucLibraryInfoBar) libraryInfoBar).LoadControls();
_libHost.Text = "Library";
}
When I close the LibraryInfoBar and refire the ShowLibraryMaintenance method, the dockwindow.Controls.Count is still greater than 0.
Thank you!
0
Accepted
Hi VSmirk,
Kind regards,
Julian Benkov
the Telerik team
In this case you can change the close action of created HostWindow:
...
HostWindow _libHost = rdMainDock.DockControl(libraryInfoBar, DockPosition.Left);
_libHost.CloseAction = DockWindowCloseAction.CloseAndDispose;
...
Kind regards,
Julian Benkov
the Telerik team