What's new

C# Update Panel Content Using UserControl

FourBytes

Honorary Poster
Joined
Feb 26, 2018
Posts
554
Reaction
61
Points
236
I tried doing this You do not have permission to view the full content of this post. Log in or register now. and in my case user controls gamit ko. Pero nung ginamit ko nageerror sya ito yung error message:
Screenshot (316).png




Ito po yung UI nitong ginagawa ko. Tas pagclick ko dapat ng products magloload dun sa content yuung usercontrol na para sa products. Gumagamit po ako ng usercontrol para sa header(home, product...) at para dun sa main content.
Screenshot (317).png

hindi ko rin po alam kung anong kelangan kong ayusin. Nung unang attempt ko po kase inedit ko yung designer. Tapos ginawa kong static yung panel para maaccess from user control. Pero nagaauto modify sya at bumabalik sa dati. At sabi sa article di dapat gawing static yun at may mga tamang way para dun pero diko po alam pano iaapply ng ayos hahah. Sana manotice.

Update: I did some more researches and this is exactly what I wanted: You do not have permission to view the full content of this post. Log in or register now. but I want to do it in a simple desktop application and i dont know how to do it well.
 

Attachments

Last edited:
Sa ganyan po . need mo muna ng dalawang panel . panel1 para sa mga links mo at panel2 para sa content mo . then pag nakagawa ka na ng user control , e call mo na sa sa panel2 ( pero dun ka maglagay ng code sa "product button" mo )
 
meron ka po bang example or natry mo na ba? yun kase yung problema ko dito hindi ko sya macall o pano ko icacall
 
[XX='FourBytes, c: 1063893, m: 1092821'][/XX] may panel na kase ako dun. kaso diko matawag o pano tatawagin. Ang mga nakikitang kong suggestion ay yung delegate kaso di ko alam kung pano gamitin e
 
[XX='FourBytes, c: 1063896, m: 1092821'][/XX]


Ganito ba gusto mong mangyari ?
 

Attachments

@FourBytes..ganito nalang gawin mo para call mo yung user control .

Sa properties : Yung Modifiers ng Main content na panel mo palitan mo ng " protected internal"

Sa usercontrol mo, double click mo at
Lagay mo tong code sa ibaba ng.

Public partial class UserControl:Control{
-----------------------------
private readonly Form _f @ Appli..ation.OpenForms["Form1"];

private static UserControl2 _instance;
public static UserControl2 Instance
{
get
{
if (_instance == null)
_instance @ new UserControl..();
return _instance;

}
}
------------------------
Palitan mo nalang yung "UserControl2" na name na exact sa gawa mong usercontrol

At para ma call yung user control , lagay mo to sa code ng button mo.
-----------------------------
if (!panel2.Controls.Contains(UserControl1.Instance))
{
panel2.Controls.Add(UserControl1.Instance);
UserControl1.Instance.Dock @ Do..kStyle.Fill;
UserControl1.Instance.BringToFront();
}
else
{
UserControl1.Instance.BringToFront();
}
}
----------------------------
Palitan mo nalang ng exact name na gamit mo sa usercontrol at panel




, Sana makatulong
 
Last edited:
@layer..post: 18089702 said:
@FourBytes..ganito nalang gawin mo para call mo yung user control .

Sa properties : Yung Modifiers ng Main content na panel mo palitan mo ng " protected internal"

Sa usercontrol mo, double click mo at
Lagay mo tong code sa ibaba ng.

Public partial class UserControl:Control{
-----------------------------
private readonly Form _f @ Appli..ation.OpenForms["Form1"];

private static UserControl2 _instance;
public static UserControl2 Instance
{
get
{
if (_instance == null)
_instance @ new UserControl..();
return _instance;

}
}
------------------------
Palitan mo nalang yung "UserControl2" na name na exact sa gawa mong usercontrol

At para ma call yung user control , lagay mo to sa code ng button mo.
-----------------------------
if (!panel2.Controls.Contains(UserControl1.Instance))
{
panel2.Controls.Add(UserControl1.Instance);
UserControl1.Instance.Dock @ Do..kStyle.Fill;
UserControl1.Instance.BringToFront();
}
else
{
UserControl1.Instance.BringToFront();
}
}
----------------------------
Palitan mo nalang ng exact name na gamit mo sa usercontrol at panel




, Sana makatulong
tatry ko po sa isang araw unahin ko muna tapusin lahat ng ui. Thankyou :>
 
Hindi mo pwede i-update yung user control from another thread.

Sa main thread or the UI thread lang pwede i-update ang UI components.

Use another thread for your extensive processing but after that, update the ui from the main ui thread pa rin.
 

Similar threads

Back
Top