|
Even if the numbers of this elaboration are quite small (inthe sense that the force that I apply is in the unit order like 1, 2, 3 ,4 .... and the parameters of the filters lead to other small numbers and so the data to exchange with the SyncWrite are small (example < 10) the only way I found is to divide this number by 1 million within the c# code and then on the PLC side multiply by 1 million. (1 million is the best solution I found. I tried also 10'000 or 100'000 but with them sometimes an access violation is generated. Probably, using factor greater than 1 million can even better the situation, I do not know)
|
|
|
|
|
I have a databinding issue with a numericupdown control bound to a bindinglist of objects. The updown control is located on a usercontrol. The controls can be loaded with values from a file located in a defaults xml file. The databinding works as it should upon loading the defaults file the first time. If during the session, I want to reload the defaults the databinding is lost. I can see that the values are loaded in correctly, but the numericupdn doesn't change value. here's a simplified version of my code to help explain.
Object class:
public class Garage :
{
public BindingList<DrawerData> Drawer = new BindingList<DrawerData>
{
new DrawerData(),
new DrawerData()
};
}
public class DrawerData : INotifyPropertyChanged
{
private decimal _NumberOfTools;
public event PropertyChangedEventHandler PropertyChanged;
public decimal NumberOfTools
{
get { return _NumberOfTools; }
set {
if (_NumberOfTools != value)
{
_NumberOfTools = value;
OnPropertyChanged("NumberOfTools");
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName] string PropertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(PropertyName));
}
}
Usercontrol class:
public partial class UcDrawer : UserControl, INotifyPropertyChanged
{
private readonly Garage _Garage;
private readonly int Drw
BindingSource bindingSource = new BindingSource();
public event PropertyChangedEventHandler PropertyChanged;
public UcDrawer(int drw,Garage garage)
{
_Garage = garage;
Drw = drw;
bindingSource.DataSource = _Garage.Drawer[Drw];
}
private void UcDrawer_Load(object sender, EventArgs e)
{
UpDnSettingsNumberOfTools.DataBindings.Add(new Binding("Value", bindingSource, "NumberOfTools", true, DataSourceUpdateMode.OnPropertyChanged));
}
}
Form where usercontrol is used (it's loaded into tabpages in a tabcontrolon the form):
public partial class FrmGarage : Form
{
private readonly int Drw;
private readonly Garage _Garage;
public FrmGarage(int drw, Garage garage )
{
InitializeComponent();
Drw = drw;
_Garage = garage;
}
private void FrmGarage_Load(object sender, EventArgs e)
{
for (int i = 0; i < ch; i++)
{
AddTab(i + 1);
}
}
private void AddTab(int ChNum)
{
UcDrawer ucDrawer = new UcDrawer(Drw, _Garage) { Dock = DockStyle.Fill };
TabPage myTabPage = new TabPage();
myTabPage.Controls.Add(ucDrawer);
GarageTabControl.TabPages.Add(myTabPage);
myTabPage.Name = "Drawer" + Drw;
myTabPage.Text = "Drawer " + Drw;
}
}
}
Main form (has buttons on a side list that load different forms into a panel, i'll only include the garage one for simplicity)
public partial class Form1 : Form
{
public Garage garage;
readonly private FrmGarage FrmGarage_vrb;
private Form ActiveMainForm = null;
public Form1()
{
InitializeComponent();
garage = new Garage();
FrmGarage_vrb = new FrmGarage(2, garage) { Dock = DockStyle.Fill, TopLevel = false, TopMost = true };
}
private void MainButtonListClickAction(Button buttonClicked, Form formActivated)
{
pnlNav.Height = buttonClicked.Height;
pnlNav.Top = buttonClicked.Top;
this.pnlFormLoader.Controls.Clear();
this.pnlFormLoader.Controls.Add(formActivated);
formActivated.Show();
ActiveMainForm = formActivated;
}
public void BtnOverride_Click(object sender, EventArgs e)
{
MainButtonListClickAction(BtnGarage, FrmGarage);
}
private void BtnMainNew_Click(object sender, EventArgs e)
{
XmlSerializer serializer = new XmlSerializer(typeof(BindingList<DrawerData>));
XmlReader reader = XmlReader.Create("defaults.xml");
garage.Drawer = (BindingList<DrawerData>)serializer.Deserialize(reader);
reader.Close();
}
|
|
|
|
|
Didn't see anything in there that looked like a "numeric up/down control".
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
|
|
|
|
|
It's in the UcDrawer class. The usercontrol layout was made in the design view. It is the UpDnSettingsNumberOfTools control located in this line:
UpDnSettingsNumberOfTools.DataBindings.Add(new Binding("Value", bindingSource, "NumberOfTools", true, DataSourceUpdateMode.OnPropertyChanged));
|
|
|
|
|
Just a guess, since Windows Forms seem to be morphing into WPF ... Changing / selecting tabs fires its own loaded and unloaded events (in WPF) and it looks like your UpDown is on a tab.
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
|
|
|
|
|
@PIEBALDconsult, sorry for trouble, but the article is deleted and I lost your comment "Could be simplified a bit". Can you remind me the link (on stackoverflow.com) to your solution? Thanks.
|
|
|
|
|
Most likely I was pointing out that typeof(T).GetFields is better than System.Enum.GetNames
and that using ToString on an enem value is better than trying to do it yourself.
|
|
|
|
|
|
PIEBALDconsult wrote: typeof(T).GetFields is better than System.Enum.GetNames
Enum.GetNames calls typeof(T).GetEnumNames , which then calls typeof(T).GetFields , so there's not going to be a huge difference.
However, GetEnumNames sorts the names by the value of the enum member, so there may be a very small performance hit there.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Right. Sorting is unnecessary as we're just adding them to a Dictionary anyway and losing the order.
Not a huge difference performance, particularly as it should happen only once per run and an enum should have few members to begin with.
My earlier comment on an "article" also pointed out that the Dictionary (ies) can be static because they don't change.
I'll also add though, that my implementation also supports having a DescriptionAttribute on each member and that can only be retrieved by retrieving the members (fields), not simply enumerating the names.
Plus... I allow finding an enum value by an abbreviated name, not just the full name, but that's not often useful.
|
|
|
|
|
How C# handles binary files?
I already know how to read binary files with the "ReadAllText" command.
|
|
|
|
|
Member 14773258 wrote: I already know how to read binary files with the "ReadAllText" command. Then, unfortunately, you do not know how to read binary files. If you read a binary file as text then it is very likely that the data will be corrupted as the system tries to interpret characters such as return (\r ) and line feed (\n ). To read binary files correctly you must read them in raw mode into arrays of pure bytes. From there you need to know the structure of the data in the files before you can do anything useful with it.
|
|
|
|
|
You very definitely don't read binary file data with ReadAllText - you need ReadAllBytes[^] which returns a byte[] instead of a string.
Strings are made of characters, which are generally variable length: they could be 8 bit, they could be 16 - and reading binary data as text is a very good way to corrupt it beyond hope of recovery.
This may help: ByteArrayBuilder - A StringBuilder for Bytes[^] it allows you to apply some "structure" to a binary file and read it in a "sensible" way. If nothing else, it shows one way to handle binary data files, but if your data files already exist and you must read them, then you will probably need to take a good hard look at the file format before you get started - there will be a structure applied to it, but what structure depends on the developer who produced them!
If you are to produce your own dtaa files, then it's probably a better idea to look at using JSON or even XML instead of binary data - it's much, much easier to handle I/O as both can "fill classes" for you when your read or write the data. Saves a whole load of work!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
how to create this program??
a program that will ask the user to enter positive number and loop/ continue until the user input a negative value and stops the loop.
The program will display
● The total number of positive numbers input
● The maximum (Highest) value
● The minimum (Lowest) value
● The equation
● And the average
Note:
● When the input is ZERO, the program will display a message that tells the user must input a positive or negative value, and ask the user to enter again a value
● ZERO will be discarded
|
|
|
|
|
We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.
So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.
If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
First C# Program
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
|
|
|
|
|
I'd use a Consol application. The only thing I don't understand is what displays "The equation" means?
|
|
|
|
|
I suspect 'equation' means sum. Probably a translation issue.
|
|
|
|
|
I want to make a server and client side WITSML (for Oil & Gas Wells Drilling Data Send/Receive). There are some SDKs here: (WITSML api library for .Net / C# client apps?). I surfed though the internet, but i have not been found any code example or guide to use them.
My Question:
==>.Are There any code example to develop a WITSML and/or WITS server and Client side software in C#?
Thank you in advance.
|
|
|
|
|
Member 13325846 wrote: Are There any code example If Google does not find any then you can assume probably not. It is always possible that you are the first to want to do this.
|
|
|
|
|
|
I have this code
public partial class TrimOptions : Form
{
public bool trimFirst { get; set; } = false;
public bool trimLast { get; set; } = false;
public bool ifBlank { get; set; } = true;
public TrimOptions()
{
InitializeComponent();
chkTrimFirst.DataBindings.Add(new Binding("Checked", trimFirst, null, false, DataSourceUpdateMode.OnPropertyChanged));
chkTrimLast.DataBindings.Add(new Binding("Checked", trimLast, null, false, DataSourceUpdateMode.OnPropertyChanged));
chkIfBlank.DataBindings.Add(new Binding("Checked", ifBlank, null, false, DataSourceUpdateMode.OnPropertyChanged));
} Whatever I set the properties to in code is reflected in the UI when the form is displayed. So far, so good. However, the user clicking the checkboxes does not set the properties, and setting the properties programmatically does not change the UI (nor the Checked property of the control).
I would like programmatic changes to the properties to update the UI, and I would like the user changing the UI to update the properties. How to do that?
modified 14-Feb-21 13:43pm.
|
|
|
|
|
|