|
Set the popup forms TopMost property to true and use the Form.Show method instead of Form.ShowDialog
That way, it'll "float" above Form1, and you will still be able to enter data in the Form1 Textbox.
Sent from my Amstrad PC 1640
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
You're welcome!
Sent from my Amstrad PC 1640
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
You can set the 'Owner property of the pop-up Form to be the first Form ... which I assume is the Main Form. That will guarantee that when you show the pop-up, it will remain "above" the Main Form.
To get further assistance, I suggest you describe what your goal is in more detail: what is the relation of data the user enters on the Main Form to the what is displayed on the pop-up Form ?
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
As a beginner in CSharp, how do i differentiate between a class and a method. Thanks
|
|
|
|
|
A class contains constructors, members, properties, and methods.
For example:
class Complex
{
private double real;
private double imag;
public Complex()
{
real = 0.0;
imag = 0.0;
}
public Complex(double x)
{
real = x;
imag = 0.0;
}
public Complex(double x, double y)
{
real = x;
imag = y;
}
public double Real { get; set; }
public double norm()
{
return real * real + imag * imag;
}
};
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
You might want to start with fundamentals. Firts: Google is your friend, i.e. learn to do some independent research.
There's an in-depth Object Oriented Design primer intended just for folks like you at:
Introduction to Object Oriented Programming Concepts (OOP) and More
"Never attribute to malice that which can be explained by stupidity."
- Hanlon's Razor
|
|
|
|
|
Simple: a class starts with <public|private|protected|internal|protected internal> class followed by the class name.
A method starts with <public|private|protected|internal|protected internal> followed by the return type (or void ) then the method name and a pair of brackets containing any parameters.
Plus, a method can only be defined inside a class, and not the other way round.
Sent from my Amstrad PC 1640
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
A Class is a something; a Method does something.
A Class is a blue-print for creating a structure: the structures created from a Class definition are instances of the Class.
Classes can contain other Class definitions, Methods, Fields.
A Method can accept parameters when it is invoked.
That's just the start ...
«... thank the gods that they have made you superior to those events which they have not placed within your own control, rendered you accountable for that only which is within you own control For what, then, have they made you responsible? For that which is alone in your own power—a right use of things as they appear.» Discourses of Epictetus Book I:12
|
|
|
|
|
I many projects I have had a similar type of problem that I have not found a good general solution to.
Assuming that I have many different lines on a Canvas that are all organized in the flat storage Canvas.Children but I want these lines to be grouped by the object they are trying to draw. Like all lines in a Ball is grouped together and can be removed by a single checkbox click and at a higher level, I can remove the entire football field etc. The only way I found out to do this was through looping through everything every time I was adding, changing and removing it, basically involving recursion.
Does anyone have some good ideas or practices for solving this?
|
|
|
|
|
I would normally base this type of thing on working with an underlying model using MVVM. Basically, I would have something like a Shape model which contained an ObservableCollection of Lines. All you would need to do then is remove the Shape and clear the Lines collection and the related items would be removed from the screen. Without seeing your code, I can't say whether or not this is feasible with the architecture you currently have in place.
This space for rent
|
|
|
|
|
At the lowest level, I have a class that inherits FrameWorkElement and use drawing visuals to actually render the objects. This is because I don't only have lines but Bezier curves etc. The problem was that I wanted to group things at an arbitrary deep levels
MyDrawingFile
-Road
--Car
---Wheels
----Rims
----Tires
---Lights
-----StopLights
-----HeadLights
---Windows
-House
So if I wanted to disable everything but the House I basically had to traverse all the objects and its children under the ObservableCollection<road> and then manually remove the objects in the Canvas.
I basically set up something like:
public abstract class HierarchyBase : INotifyPropertyChanged
{
private ObservableCollection<HierarchyBase> children = new ObservableCollection<HierarchyBase>();
public ObservableCollection<HierarchyBase> Children
{
get { return children; }
set { children = value; }
}
public string Name { get; set; }
private bool pIsEnabled;
public bool IsEnabled
{
get { return pIsEnabled; }
set { pIsEnabled = value;
StateUpdated();
OnPropertyChanged();
}
}
private bool pIsVisible;
public bool IsVisible
{
get { return pIsVisible; }
set {
pIsVisible = value;
StateUpdated();
OnPropertyChanged();
}
}
private void StateUpdated()
{
if (this is IDrawing)
{
((IDrawing)this).Redraw(IsVisible);
}
foreach (HierarchyBase child in Children)
{
if (!this.IsEnabled || !this.IsVisible)
{
child.IsVisible = false;
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged([CallerMemberName]string caller = "")
{
var handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(caller));
StateUpdated();
}
}
}
But then binding was a big issue, so I thought is somewhat clumsy.
|
|
|
|
|
List<object> Ball = ...
...
Canvas.Children.Add( line );
Ball.Add( line );
...
Ball.ForEach( l => Canvas.Children.Remove( l as UIElement ) );
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Yes, something like this is what I tried to do, but I found it to be very messy. No binding and I have to resort to storing the connection to a canvas in the code behind. It does work but not really good MVVM?
|
|
|
|
|
It's a generic "infrastructure" helper "pattern"; nothing to do with "MVVM".
Plumbing.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Not initially no. But as soon as I had the treeview up and running with binding:
<TreeView x:Name="tree">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type local:HierarchyBase}" ItemsSource="{Binding Children}" >
<TextBox Text="{Binding Name}"/>
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>
This was very neat, but now how to bind the canvas to the code behind? I thought this was very messy.
public abstract class HierarchyBase : INotifyPropertyChanged
{
public HierarchyBase()
{
Delete = new RelayCommand( CanDelete, DeleteThis);
children.CollectionChanged +=ItemChildren_CollectionChanged;
}
public Canvas myCanvas;
private HierarchyBase _parent;
private void ItemChildren_CollectionChanged(object sender,NotifyCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Add)
{
foreach (var item in e.NewItems)
{
((HierarchyBase)item)._parent = this;
((HierarchyBase)item).myCanvas = this.myCanvas;
}
}
if (e.Action == NotifyCollectionChangedAction.Replace)
{
}
if (e.Action == NotifyCollectionChangedAction.Remove)
{
foreach (var item in e.OldItems)
{
((HierarchyBase)item)._parent = null;
((HierarchyBase)item).myCanvas = null;
}
}
if (e.Action == NotifyCollectionChangedAction.Move)
{
}
}
private ObservableCollection<HierarchyBase> children = new ObservableCollection<HierarchyBase>();
public ObservableCollection<HierarchyBase> Children
{
get { return children; }
set { children = value; }
}
public ICommand Delete { get; set; }
private bool CanDelete(object obj)
{
return IsEnabled;
}
private void DeleteThis(object obj)
{
this._parent.Children.Remove(this);
}
public string Name { get; set; }
private bool pIsEnabled = true;
public bool IsEnabled
{
get { return pIsEnabled; }
set { pIsEnabled = value;
OnPropertyChanged();
}
}
private bool pIsVisible = true;
public bool IsVisible
{
get { return pIsVisible; }
set {
pIsVisible = value;
OnPropertyChanged();
}
}
private void StateUpdated()
{
if (this is IDrawing)
{
((IDrawing)this).Redraw(IsVisible);
}
foreach (HierarchyBase child in Children)
{
if (!this.IsEnabled || !this.IsVisible)
{
child.IsVisible = false;
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged([CallerMemberName]string caller = "")
{
var handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(caller));
StateUpdated();
}
}
}
Any ideas on how to bind the canvas to the code behind in XAML? All I came up with was to bind the canvas manually to the first HierarchicalBase item when I loaded the program. I just thought I was messy and ugly.
|
|
|
|
|
What we are doing is "shadowing"; we are just going about it in different ways depending on the circumstances.
Your "hierarchyBase" is "view" support code; in particular, Canvas; infrastructure code.
Not sure how your "tree" relates to your earlier "ball"; so I can't visualize or comment on it.
Your architecture is "component based" (versus "view" based); or "views with components"; it should use appropriate patterns.
I would consider integrating with Unity.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
modified 3-Aug-18 14:18pm.
|
|
|
|
|
I have a data file called Access 2003 Table The question "TABCAUHOI" has the following fields:
ID int;
NOIDUNG memo;
The "NOIDUNG" field has data type as memo, I pour data from excel text file into this table in this access file to check the contents are full as excel file, in C # I query read data into DataTable dt = query 1 message of a content, when debugging Debug.Print (dt.Rows [0] ["NOIDUNG"]. ToString ()); Only get 255 characters in the first string, characters after 255 characters later lost, want to get everything into the DataTable how to do ?
|
|
|
|
|
Start by checking your data: look directly at the DB content using Access itself and ensure that the data as entered is complete, and longer than 255 characters. Do not assume it is right: check it.
If it isn't, look at the software you used to enter it.
If it is, then use the debugger to look directly at the DataTable as soon as you have filled it, and check exactly what is in there - it should be the same.
If it isn't, check your loading code and make sure you are referring to the same DB file you checked earlier.
If it is, put the value from the DB into a variable and look at it using the debugger:
object o = dt.Rows [0] ["NOIDUNG"];
string s = o.ToString (); Check exactly what you have there.
We can't do that for you!
Sent from my Amstrad PC 1640
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I checked the data from excel to access is good but from Table Access to DataTable is not good. From Table access to the DataTable get the first 255 characters, the characters after 255 are lost. You note: I have no excel data errors on the table access, I have errors from the Table access into the C # winform DataTable and use the OleDb connection.
I tried the cases below to give the one result:
Debug.Print(dt.Rows[0]["NOIDUNG"].ToString());
Debug.Print(Convert.ToString(dt.Rows[0]["NOIDUNG"]));
object o = dt.Rows[0]["NOIDUNG"];
string s = o.ToString();
Debug.Print(s);
|
|
|
|
|
MS Access itself limits the 'char' data type to 255 characters.
To "pour' the data from excel to MS Access you must be using some sort of conversion. If the conversion only allows for 'char' or if you explicitly set it to 'char' then it will only move 255 characters.
|
|
|
|
|
He's using a "Memo"; which supposedly holds 64K.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
And yet he specifically noted that the actual process was producing only and exactly 255 characters.
I was suggesting that the evidence strongly suggested that the conversion process was not in fact using Memo but Char. So something in the steps, presumably multiple, that comprise the entire process was introducing Char.
|
|
|
|
|
You haven't shown any of your "pouring" code.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|