|
I swear I have been searching for an answer for hours but could not find any understandable example or article How do I make a property of a Winform usercontrol retain it's design time value? I added a new UserControl object. I put a label on the control. Added a property called "KeyText". I saw in few articles the attribute "DesignerSerailizationVisibility" mentioned so I added it as well.
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public string KeyText
{
get { return label1.Text; }
set
{
label1.Text = value;
}
} In the control, the default value of label1.Text is "X".
Then I added the control to a form. The property "KeyText" showed as one of the properties of the control. Great. So I changed it to "A". The design-time form showed A". Great. I compiled and ran the program - the control on the form showed "X" instead of "A".
What do I need to change to make the property persisteable? In VB6 I use something called PropBag to save and read design time properties.
|
|
|
|
|
OK, I added a new UserControl (called MyControl) to my project, dropped a label on it called MyLabel.
I changed it's Text property to "Default".
I added a string property called LabelText to the control:
public string LabelText
{
get
{
return MyLabel.Text;
}
set
{
MyLabel.Text = value;
}
}
And compiled the app.
Then I dropped two instances of MyControl (MC1 and MC2) onto my form.
I changed the LabelText property of MC2 to "Revised" in the designer and ran the app.
MC1 had "Default", MC2 had "Revised"
So what did I do that you didn't?
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
modified 14-Apr-20 2:40am.
|
|
|
|
|
Crazy Joe Devola wrote: [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
That line is the problem. The documentation isn't particularly clear, but:
With the DesignerSerializationVisibilityAttribute , you can indicate whether the value for a property is Visible , and should be persisted in initialization code, Hidden, and should not be persisted in initialization code, or consists of Content , which should have initialization code generated for each public, not hidden property of the object assigned to the property.
The property value is a String . The String type doesn't have any public properties which can be set, so no initialization code will be generated.
Either set it to DesignerSerializationVisibility.Visible , or remove the attribute.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
thank you. It is working now.
|
|
|
|
|
When i give print on first time it works , but when we click again it over printing
my print document code below
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.HasMorePages = false;
gf = e.Graphics;
lsx = 10;
lex = 797;
Brush brblack = new SolidBrush(Color.Black);
Pen p1 = new Pen(brblack);
int lpx = 10;
if (pgcount < 2)
{
dgline = 370;
dgtxt = 390;
dgdc = 350;
lsy1 = 345;
e.Graphics.DrawImage(img, -10, 0);
e.Graphics.DrawImage(img1, -10, 1000);
e.Graphics.DrawString(txtdate.Text, new Font("Times New Roman", 12, FontStyle.Bold), Brushes.Green, 600, 135);
e.Graphics.DrawString("Ref :" + txtqtnno.Text, new Font("Times New Roman", 12, FontStyle.Bold), Brushes.Black, 600, 155);
e.Graphics.DrawString("M/S " + txtclientname.Text, new Font("Times New Roman", 12, FontStyle.Regular), Brushes.Black, lpx, 170);
e.Graphics.DrawString(companyadd1, new Font("Times New Roman", 12, FontStyle.Regular), Brushes.Black, lpx, 195);
e.Graphics.DrawString(companyadd2, new Font("Times New Roman", 12, FontStyle.Regular), Brushes.Black, lpx, 220);
e.Graphics.DrawString("Kind Attn: " + cusname + "\nMob: " + cusno + ", E-mail: " + cusemail, new Font("Times New Roman", 12, FontStyle.Regular), Brushes.Black, lpx, 245);
e.Graphics.DrawString("Dear Sir,", new Font("Times New Roman", 12, FontStyle.Regular), Brushes.Green, lpx, 295);
e.Graphics.DrawString("sub : " + qtnsubject, new Font("Times New Roman", 12, FontStyle.Regular), Brushes.Green, lpx, 320);
}
else
{
lsy1 = 135;
dgline = 155;
dgtxt = 175;
dgdc = 137;
}
e.Graphics.DrawLine(p1, new Point(lsx, lsy1), new Point(lex, lsy1));
e.Graphics.DrawString(" Sr. no\t\t Descrption\t\t\tPrice\t Qty\t Amount", new Font("Times New Roman", 12, FontStyle.Bold), Brushes.Green, lpx, dgdc);
e.Graphics.DrawLine(p1, new Point(lsx, dgline), new Point(lex, dgline));
for (;drc<dataGridView2.RowCount - 1; drc++)
{
SizeF sf = gf.MeasureString(dataGridView2.Rows[drc].Cells[1].Value.ToString(), new Font(new FontFamily("Times New Roman"), 12F), 200);
rowspace = Convert.ToInt32(sf.Height);
dgtxt = dgtxt + 10;
chkpghgt = ((rowspace + dgtxt)*1);
if (chkpghgt > 1000)
{
e.HasMorePages = true;
pgcount++;
break;
}
gf.DrawString((drc+1).ToString(), new Font(new FontFamily("Times New Roman"), 12F), Brushes.Black, new RectangleF(new Point(50, dgtxt), sf), StringFormat.GenericTypographic);
gf.DrawString(dataGridView2.Rows[drc].Cells[1].Value.ToString(), new Font(new FontFamily("Times New Roman"), 12F), Brushes.Black, new RectangleF(new Point(120, dgtxt), sf), StringFormat.GenericTypographic);
gf.DrawString(dataGridView2.Rows[drc].Cells[3].Value.ToString(), new Font(new FontFamily("Times New Roman"), 12F), Brushes.Black, new RectangleF(new Point(405, dgtxt), sf), StringFormat.GenericTypographic);
gf.DrawString(dataGridView2.Rows[drc].Cells[4].Value.ToString(), new Font(new FontFamily("Times New Roman"), 12F), Brushes.Black, new RectangleF(new Point(550, dgtxt), sf), StringFormat.GenericTypographic);
gf.DrawString(dataGridView2.Rows[drc].Cells[5].Value.ToString(), new Font(new FontFamily("Times New Roman"), 12F), Brushes.Black, new RectangleF(new Point(690, dgtxt), sf), StringFormat.GenericTypographic);
dgline = dgtxt + rowspace + 10;
e.Graphics.DrawLine(p1, new Point(lsx, dgline), new Point(lex, dgline));
dgtxt = dgline;
}
e.Graphics.DrawLine(p1, new Point(lsx, lsy1), new Point(lsx, dgline));
e.Graphics.DrawLine(p1, new Point(lsx+80, lsy1), new Point(lsx+80, dgline));
e.Graphics.DrawLine(p1, new Point(370, lsy1), new Point(370, dgline));
e.Graphics.DrawLine(p1, new Point(485, lsy1), new Point(485, dgline));
e.Graphics.DrawLine(p1, new Point(625, lsy1), new Point(625, dgline));
e.Graphics.DrawLine(p1, new Point(lex, lsy1), new Point(lex, dgline));
}
|
|
|
|
|
You have an awful lot of objects there that should be disposed of. GDI resources are finite so every time you hit the event handler you are consuming resources without freeing them up. For instance, when you instantiate a Font, that's disposable so you should Dispose it.
|
|
|
|
|
At few places I am reading that multi threading is a process in which we run multiple threads under a process. But at few places I can see that multi threading is a process of executing multiple threads. Like Working on word and listening music from different application. As they both are having different process like word.exe and vlc.exe.
So what should be correct way so say about multi threading?
|
|
|
|
|
Multi-threading in the context of writing an app is the system of splitting work into multiple threads within a single process (the app execution space) to either free one thread (normally the GUI thread) of work, or to process data in parallel for higher throughput.
In this context, there is one process, which consists of memory plus a number of threads (which may change at run time)
The "working on word and listening to music" isn't really multi-threading - it's multi-process as the threads do not share a common execution space, and cannot access each other's memory. It's closer to the concept of "multitasking*" than "multi-threading", although it does involve separate threads as each process must have at least one active thread in order to remain in existence.
* Multitasking in the sense that "women are supposed to be better at it than men" but actually there isn't a difference
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Hello Sir, I am trying to Read Tag (Value & Timestamp) from Mitsubishi MX OPC using C# Titatanium Library and insert those values in MySQL Database . Is that right way of proceeding for Reading value from OPC Server, Is there any Restriction in using Titanium Library. Please suggest a solution if any alternate Library to Read Value from OPC Server.
Regards,
Praveen cp
|
|
|
|
|
If it works, it works. Your experience is not dependent on someone else's experience.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
If it works, it works. Your experience is not dependent on someone else's experience.
Hello Sir, I really don't know what you are mentioning about. Just I asked that is there Limitations or Restriction using Titanium Library?
|
|
|
|
|
What is OPC?
What is Titanium Library?
Have you read the doco on both (if it exists)?
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
That's partly going to depend on what version of OPC DA the Mitsubishi MX uses (assuming you are confining yourself to the DA here and aren't interested in AE at all). All your other questions really flow from this.
|
|
|
|
|
Inside a textbox i add many lines of data, ended with a newline(\r\n) for each of it.
For example:
Aaa
Bbb
Ccc
Each line must be read in a backgroundWorker1_DoWork event. Basically, is a time delay of a couple of seconds between jumping to the other line to be read and processed.
My problem is this: - If i add a new line, WHILE the DoWork is running, the textbox.List.lenght is bigger by 1. What should LOAD that updated List, and pass the next line consecutively, to the worker?
At this point i am blank.
What i did so far...
I inverted the list
why? because my processing is not disturbed by each new line added on top, but is accumulating lines at the end, maintaining the lines numbers and contents when it jumps to the next line.
list1.Clear(); label1.Text = "";
list1.AddRange(textBox1.Lines);
list1.Reverse();
for (int i = 0; i < list1.Count; i++)
{
label1.Text += list1[i] + nl;
}
And now the output is:
Ccc
Bbb-updateLine
Aaa
a1-nl
a2-nl
One solution to updating lines by mistake, and avoid re-processing them, is to completely erase the completed "worked" lines from the List and update somewhere else the finished lines.
|
|
|
|
|
i figure out the solution, but i'm still curious whats your resolve though.
|
|
|
|
|
Set up a separate "concurrent queue" for the background worker to access "new lines".
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Given the different actions the user can perform on the content of the TextBox ... paste, delete selected lines, etc. ...
I think your strategy should be to perform whatever content enumeration only when the textBox is not in use.
What is the reason you think you need to use a BackGroundWorker here ?
If you must use it, look at the use of 'ManualResetEvent, and use of 'Monitor and 'Lock.
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
I set the AssemblyInfo in my app to this:
[assembly: AssemblyVersion("1.0.*")]
Yet each time I compile it only increments the Revision, not the Build #. So I end up with something like "1.0.7404.29813", with only the last part ever being incremented.
I display the version info in the status bar of my app, and that's a lot for the users to read back to me during debugging. Is there a way to increment the Build portion each time I compile?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
According to the documentation[^], the default build number should increment daily. You should only ever get 7404 on 9th April 2020.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
suppose you have two lists of the same size, i.e. same number of elements
List<int> a, List<int> b
is it possible to traverse the two lists simultaneously and compare the values? Element 1 in list a to element 1 in list b, element 2 in list a to element 2 in list b, etc. I use a Foreach when traversing lists, but am unsure of how to do a side by side comparison of list b when I am traversing list a.
Thanks
|
|
|
|
|
Use a for instead of a foreach :
for (int i = 0; i < a.Length && i < b.Length; i++)
{
if (a[i] == b[i])
{
...
}
}
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Lists work just like arrays, so you can use either an enumerator (foreach) or you can use an index value:
for(int index = 0; index < someValue; ++index)
{
if (a[index] == b[index])
{
}
else
{
}
}
|
|
|
|
|
If the "lengths" of a and b are equal, you can maintain your own index:
int i = 0;
foreach ( int value in a ){
bool result = (value == b[i++]);
}
Note the suffix (++) operator in this case.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
You could also use the Zip extension method, which takes a lambda with two arguments, which is called with the corresponding elements. It yields a IEnumerable of the results of those lambda calls.
var a = {1,2,3,4};
var b = {2,3,4,5}
var c = a.Zip(b, (aa, bb)=> aa * bb).ToList();
var d = {…};
var e = {…};
if (d.Zip(e, (dd, ee)=> dd==ee).All())
{
Truth,
James
modified 13-Apr-20 8:01am.
|
|
|
|
|
One
I have a WPF window which displays a datagrid of Project info. At the top, above the datagrid, are two combo boxes; one for Companies and the other for Project Status. The user can then filter the datagrid by either the Project's company, the Project's status, or both.
When the user opens the window, I want the combo boxes to load asynchronously so the window stays responsive. I want the window to appear, and then load the combobox data. So I have the Window_Loaded event bound to a command, which fires this:
private async Task<bool> WindowLoadedExecuted()
{
await LoadLists();
await LoadProjects();
return true;
}
private async Task<bool> LoadLists()
{
var companyHeaders = await AppCore.BizObject.GetCompanyHeadersAsync();
CompanyHeaders = new List<CompanyHeaderEntity>(companyHeaders);
var projectStatuses = await AppCore.BizObject.GetLookupsAsync(Constants.LookupCategoryProjectStatuses);
ProjectStatuses = new List<LookupEntity>(projectStatuses);
return true;
}
The question here is, is there anything wrong with simply returning a Task instead of Task<bool>? Neither of these methods are going to return anything here. I'm asking because I've seen some articles and posts that say it's not a good idea, but I don't see why. Anything wrong with returning Task instead of Task<t> if there's no return value?
Two
Both of the comboboxes above can trigger a requery. By selecting either a Company or a Status to filter by, I want to reload the datagrid. So, in the properties for both, in their getters, I do:
private CompanyHeaderEntity _SelectedCompanyHeader;
public CompanyHeaderEntity SelectedCompanyHeader
{
get { return _SelectedCompanyHeader; }
set
{
if (_SelectedCompanyHeader != value)
{
_SelectedCompanyHeader = value;
RaisePropertyChanged("SelectedCompanyHeader");
new Task(async () =>
{
await LoadProjects();
}).Start();
}
}
}
To me, this makes sense because selecting a company (instead of none for All), what the user is doing is filtering the list to only those companies. So changing the SelectedCompany property should fire this off.
Yet again, I see posts that seem to discourage this, like this one. Any real reason not to do this? Or is there a better way?
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
modified 9-Apr-20 0:26am.
|
|
|
|
|