您好,
我新的WPF和C#。我想在运行时创建一个按钮,改变它的名字,然后,当我关闭的应用程序,它应该被保存,当我重新加载应用程序的按钮应该有。
在运行时创建的按钮很容易,但要找到保存的地方创建的按钮,可以是便携式(可重复使用,如果重新安装应用程序)不是最好的办法。我读过有关My.Settings进行,XAML作家,独立的存储,使用数据库,注册表等和诚实,我迷路了。
这是最佳的解决方案,以及如何实现呢?
谢谢。
麦
Inlines.Clear();
Text = null;
if (value == null) return;
StringBuilder SB = new StringBuilder();
SB.Append("<TextBlock xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">");
SB.Append(value.ToString().Replace("\r\n", "<LineBreak/>"));
SB.Append("</TextBlock>");
var TB =
XamlReader.Load(new System.Xml.XmlTextReader(
new System.IO.StringReader(SB.ToString()))) as TextBlock;
var Lista = TB.Inlines.ToArray();
foreach (var item in Lista)
{
this.Inlines.Add(item);
}
public bool SendMailBySmtp(string from, string to, string subject, string body)
{
try
{
// Instantiate a new instance of MailMessage
MailMessage ObjMailMessage = new MailMessage();
// Set the sender address of the mail message
ObjMailMessage.From = new MailAddress(from);
// Set the recepient address of the mail message
ObjMailMessage.To.Add(new MailAddress(to));
// Set the subject of the mail message
ObjMailMessage.Subject = subject;
// Set the body of the mail message
ObjMailMessage.Body = body;
// Set the format of the mail message body as HTML
ObjMailMessage.IsBodyHtml = true;
// Set the priority of the mail message to normal
ObjMailMessage.Priority = MailPriority.Normal;
// Instantiate a new instance of SmtpClient
SmtpClient ObjSmtpClient = new SmtpClient(str_ServerDetails);
ObjSmtpClient.Port = 25;
//ObjSmtpClient.Credentials = CredentialCache.DefaultCredentials;
if (!String.IsNullOrEmpty(str_UserName))
{
NetworkCredential ObjNC = new NetworkCredential(str_UserName, str_Password);
ObjSmtpClient.Credentials = ObjNC;
}
else
{
ObjSmtpClient.Credentials = CredentialCache.DefaultNetworkCredentials;
}
// Send the mail message
ObjSmtpClient.Send(ObjMailMessage);
return true;
}
catch (SmtpException ex)
{
//HandelError ObjhandleError = new HandelError();
//ObjhandleError.ManageError(ex.Message, "SendMailClass.sendMailbySMTP()");
//return false;
}
catch (FormatException ex)
{
//HandelError ObjhandleError = new HandelError();
//ObjhandleError.ManageError(ex.Message, "SendMailClass.sendMailbySMTP()");
//return false;
}
catch (ArgumentException ex)
{
//HandelError ObjhandleError = new HandelError();
//ObjhandleError.ManageError(ex.Message, "SendMailClass.sendMailbySMTP()");
//return false;
}
catch (InvalidOperationException ex)
{
//HandelError ObjhandleError = new HandelError();
//ObjhandleError.ManageError(ex.Message, "SendMailClass.sendMailbySMTP()");
//return false;
}
catch (System.Security.SecurityException ex)
{
//HandelError ObjhandleError = new HandelError();
//ObjhandleError.ManageError(ex.Message, "SendMailClass.sendMailbySMTP()");
//return false;
}
catch (ConfigurationErrorsException ex)// IN CASE OF SHARED HOSTING
{
//HandelError ObjhandleError = new HandelError();
//ObjhandleError.ManageError(ex.Message, "SendMailClass.sendMailbySMTP()");
//return false;
}
return false;
}