|
That's an interesting approach, one that seems like what goes on with drag-drop.
In what kind of scenario would you use this rather than just move the Control ?
thanks, Bill
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
I actually am using a proxy system. However, the main window also uses the same (similar in the case of move) system since it is a border-less form. That is why I posted this topic to begin with. I want to write one set of code for both forms and controls.
|
|
|
|
|
Only numeric textbox
private void tbxTCKimlik_KeyPress(object sender, KeyPressEventArgs e)
{
if (!(e.KeyChar >= 48 && e.KeyChar <= 57)) e.Handled = true;
if (e.KeyChar == Convert.ToChar(8)) e.Handled = false;
}
modified 6-Mar-19 9:05am.
|
|
|
|
|
Apart from being pretty poor code, what do you expect us to do with that?
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
What s the problem with codE ?
|
|
|
|
|
Undocumented, magic numbers, unnecessary else condition, doesn't work with all characters sets, difficult to reuse without copy'n'paste, can be bypassed with no effort to put non-numeric characters in the TextBox, trivial problem that has better solutions (including the use of standard controls), only works efficiently in app based code - it's a gawd awful solution for a web based project.
Even the TextBox name it's attached to violates C# naming conventions[^] ...
That's why I think it's poor quality code...
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Incidentally, I have need for a similar solution (except for my issue is with a .NET System.Windows.Forms textbox). I agree that he doesn't actually ask a question here so we are not sure how to help. However, since I am facing what appears to be a similar situation (from what I can tell...) I will try and interpret: he is probably saying that his editbox doesn't catch the backspace button. I have the same problem with an editbox that is for supplying a zip code. It works fine except that the backspace key is not accepted as a control key so it doesn't respond to backspace (the back/back delete key)
|
|
|
|
|
pr1mem0ver wrote: he is probably saying that his editbox doesn't catch the backspace button
if (e.KeyChar == Convert.ToChar(8)) Also, backspace and delete are not the same button, and have a different effect.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Yeah... already tried that. It doesn't work either.
|
|
|
|
|
Then you have an error in your code
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
@pr1mem0ver Using a sub-classed TextBox, and its KeyPress event, 'Delete is not registered because it is a Control Key.
However, 'Delete will do the usual in such a TextBox.
If you start a new post here and post your current code with a description of what your goal is, and what's not working, I'll respond in detail.
cheers, Bill
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
modified 9-Mar-19 8:01am.
|
|
|
|
|
If you think you're posting that for the benefit of others, that code will only work with keyboards that are rooted in a Latin character set. Your code is limited to the straight numeric values in ASCII. Try that on a Chinese or Japanese keyboard and you'll see the problem with it.
It's also not built into its own control so it can easily be reused, which itself is easy enough to do.
There are other, much better ways to do this, but I don't have the time to go into it right now.
|
|
|
|
|
Thank you for comment. This is best what I can do. If you have better solution. Please share it.
|
|
|
|
|
|
Bayram Demirci wrote: This is best what I can do. No, this is what you've done so far, and you can do better by studying the posts in this thread carefully.
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
|
namespace CustomControls
{
public enum NumModel
{
PositiveInteger,
PositiveFloat
}
public class NumberTextBox : TextBox
{
private NumModel numModel = NumModel.PositiveInteger;
public NumModel NumModel
{
get
{
return numModel;
}
set
{
numModel = value;
}
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
if ((e.KeyChar >= '0' && e.KeyChar <= '9') || (e.KeyChar == 8) || (e.KeyChar == 46))
{
if (numModel == NumModel.PositiveInteger)
{
if ((e.KeyChar == 46))
{
e.Handled = true;
}
else
{
e.Handled = false;
}
}
else
{
if ((this.Text.Contains(".") && (e.KeyChar == 46)))
{
e.Handled = true;
}
else
{
e.Handled = false;
}
}
}
else
{
e.Handled = true;
}
}
protected override void OnKeyUp(KeyEventArgs e)
{
double num;
if (this.Text != null && this.Text != "" && !double.TryParse(this.Text, out num))
{
this.Text = this.Text.Substring(0, this.Text.Length - 1);
this.Select(this.Text.Length, 0);
}
base.OnKeyUp(e);
}
}
}
|
|
|
|
|
Hi, I'd like to update an item from my collection. I used the code below but this calls the Dispose event which I'd like to avoid.
this.CurrentUser.Companies[idx] = comp;
So instead I'd like to use something like below which works and doesn't trigger the Dispose but seems inefficient with 4 calls made. Does that make sense? Can anybody please recommend a more efficient approach?
private void UpdateCompanyFields(int idx, Company comp)
{
this.CurrentUser.Companies[idx].BusinessName = comp.BusinessName;
this.CurrentUser.Companies[idx].Address.AddressOne = comp.Address.AddressOne;
this.CurrentUser.Companies[idx].Address.AddressTwo = comp.Address.AddressTwo;
this.CurrentUser.Companies[idx].Address.City = comp.Address.City;
}
|
|
|
|
|
You first line of code will not automatically "call the Dispose event" unless your Companies collection specifically does that when you overwrite an element - in which case there is probably a very, very good reason for it.
And your second code does not do the same thing at all - it overwrites parts of the class instance held by the collection which alters the instance throughout the app.
For example:
class MyClass
{
public int Value {get; set;}
public MyClass(int x) { Value = x;}
}
MyClass[] data = new MyClass[2];
MyClass x = new MyClass(333);
MyClass y = new MyClass(666);
myClass z = new MyClass(999);
myClass[0] = x;
myClass[1] = y;
myClass[0] = z;
myClass[1].Value = 111;
Changing x.Value will not affect the value in MyClass[0] and vice versa, changing the value of y will affect the value of myClass[1] and vice versa. Changing myClass[0] or z will affect both because they are the same instance.
I think you need to think a bit more carefully before you continue, and find out why the collection is calling Dispose - it implies the Company has important other info which needs to be replaced and Disposed, which your second code example does not do.
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
The real inefficiency comes from the memory management in the second instance. With your original code there is an object in memory already and this line
this.CurrentUser.Companies[idx] = comp;
simply copies the memory address of "comp" to the Companies array at index idx. However this code;
this.CurrentUser.Companies[idx].BusinessName = comp.BusinessName;
Looks at the length of comp.BusinessName, reserves the same amount of memory elsewhere, copies the contents of BusinessName into that memory, then assigns that memory address to Companies[idx].BusinessName. All that memory management makes that operation slow, and you are doing it multiple times.
There is nothing wrong with the dispose event being called, it doesn't make the code inefficient. Unnecessary memory management is more likely to be a cause of inefficiency.
|
|
|
|
|
COBOL has a MOVE CORRESPONDING that accomplishes what you want.
Internally, the compiler will still generate "4 moves". Why do you think that is?
And what part is "disposable"?
And how exactly is your code "calling Dispose"?
Or, are you bluffing?
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
The Properties > Publish page of my App shows a Publish Version of 5.0.0.7.
When I use:-
Assembly assembly = Assembly.GetExecutingAssembly();
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);
it always gives 1.0.0.0.
How do I access the version number from the properties page?
|
|
|
|
|
These are the methods I use:
public string AssemblyTitle
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
if (attributes.Length > 0)
{
AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
if (titleAttribute.Title != "")
{
return titleAttribute.Title;
}
}
return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
}
}
public string AssemblyVersion
{
get
{
return Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
}
public string AssemblyDescription
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyDescriptionAttribute)attributes[0]).Description;
}
}
public string AssemblyProduct
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyProductAttribute)attributes[0]).Product;
}
}
public string AssemblyCopyright
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
}
}
public string AssemblyCompany
{
get
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyCompanyAttribute)attributes[0]).Company;
}
}
Note that is the Executing Assembly it fetches data for - i.e. the assembly that that specific code is compiled into. If that is a DLL used by the app - i.e. a code library - it will fetch the data for the DLL, not the original EXE that called it. For the original EXE assembly data, replace GetExecutingAssembly with GetEntryAssembly
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
AssemblyVersion still returns 1.0.0.0 despite the Properties > Publish page showing 5.0.0.7. That is with GetExecutingAssembly or with GetEntryAssembly.
Am I missing something?
|
|
|
|
|
Probably, yes. From here though it's difficult to tell what.
Start by looking in the project Properties folder at the file AssemblyInfo.cs - copy and paste that so we can read it, along with the full path to the file - the version info is normally at the bottom.
Then show exactly the code you used, what it displayed, and tell us the location of the file it's in (the full path helps here as well)
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|