|
How do I implement a Window app to maximize when user moves the window from one display monitor to another. When the move occurs LocationChanged event is triggered and the window state becomes Normal.
I tried this.WindowState=FormWindowState.Maximized in the LocationChanged handler. However, the window does not maximized. Likely because it triggered circular reference. I had also implemented a module Boolean variable to avoid this. However, the window never maximized.
What is the proper way to implement this?
Thank you in advance for your response.
|
|
|
|
|
While the mouse button is down, as far as the system is concerned, the window is still moving. I would look at setting a flag in the LocationChanged event to let you know that the window is moving, and then set the FormWindowState in the MouseUp event (and then resetting that flag too, of course).
Cheers,
Mick
------------------------------------------------
It doesn't matter how often or hard you fall on your arse, eventually you'll roll over and land on your feet.
|
|
|
|
|
I think the ResizeBegin and ResizeEnd events will help you. The naming is misleading as the purpose of these events is to indicate when the form is showing the resizing border. Click and hold on the form border or caption bar and the ResizeBegin event is raised. ResizeEnd is seen on release whether or not any resizing has occurred.
Here is a trivial (and annoying) modification to a form to make it maximise when it is moved without having changed it's size.
private Rectangle? lastBounds;
protected override void OnResizeBegin(EventArgs e) {
base.OnResizeBegin(e);
System.Diagnostics.Debug.Print("EVENT ResizeBegin");
lastBounds = Bounds;
}
protected override void OnResizeEnd(EventArgs e) {
base.OnResizeBegin(e);
System.Diagnostics.Debug.Print("EVENT ResizeEnd");
if (lastBounds.HasValue) {
Rectangle previous = lastBounds.Value;
if (previous != Bounds && previous.Size == Bounds.Size) {
WindowState = FormWindowState.Maximized;
}
lastBounds = null;
}
}
In your case it would be necessary to detect the System.Windows.Forms.Screen containing the form in ResizeBegin and test for the desired destination Screen in ResizeEnd.
Alan.
|
|
|
|
|
Hi Mick, Alan
MouseUp and ResizeBegin/End works wonderfully. Thank you and Happy New Year.
|
|
|
|
|
I am attempting to simulate a mouse scroll on the desktop screen (Windows 10) and use the following:
SendMessage
(
GetDesktopWindow(),
WM_MOUSEWHEEL,
MakeWParam
(
LowWord((uint)MK_CONTROL),
HighWord
(
(uint)System.Windows.Forms.SystemInformation.MouseWheelScrollDelta
)
),
MakeLParam(0, 0)
);
const int WM_MOUSEWHEEL = 0x020A;
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", SetLastError = false)]
static extern IntPtr GetDesktopWindow();
public static ushort LowWord(uint val)
{
return (ushort)val;
}
public static ushort HighWord(uint val)
{
return (ushort)(val >> 16);
}
private int MakeLParam(int p, int p_2)
{
return ((p_2 << 16) | (p & 0xFFFF));
}
public static uint MakeWParam(ushort low, ushort high)
{
return ((uint)high << 16) | (uint)low;
}
I get stuck because I do not know what to replace MK_CONTROL constant with, which is used to create a "low word." I've searched far and wide, but can't find anything as it relates to WM_MOUSEWHEEL .
I got the algorithm itself from this page, but it's all in C++...
Ultimately, I found this article, but it does not suggest it is a constant of any kind or how to use it with SendMessage method.
|
|
|
|
|
|
I am trying to understand the DbContext class by going to its definition and look at its members.
I am confused by what I saw in DbContext's definition, all of the methods in the DbContext class only have method signatures but no body (no implementation). Please see some of the methods below.
public virtual int SaveChanges();
public virtual DbSet Set(Type entityType);
Can someone please explain why all of the methods in the DbContext class look like they are abstract methods in an abstract class or methods in an interface. If these are concrete methods why don't they have implementations?
modified 31-Dec-16 12:28pm.
|
|
|
|
|
I don't know what you're looking at but those do have implementations. They're overridable, but they do have default implementations.
Examine the source for DbContext here[^].
|
|
|
|
|
Can you give us the whole structure of the class you are looking at? You are looking at wrong place I guess.
|
|
|
|
|
Hi, thank you for replying. I have a class that inherits from the DbContext class and to go to DbContext class definition, I placed the cursor on DbContext and pressed F12.
For the most part the definition of DbContext that I saw looked like the one shown in the link provided by Dave Kreskowiak above. The only problem is that none of the methods have implementations.
modified 30-Dec-16 12:11pm.
|
|
|
|
|
You're looking at the peek definition window. It shows the definition for the type or method symbol your cursor is currently on. It can not show implementation code it doesn't have access to like in an external DLL. In that case it only displays metadata.
|
|
|
|
|
hello Friend i have to know how to split below string in particular part. i have find this type of string in bar-code scanner as a input
I have a input
Hide Copy Code
0.1042.5140.7043.037.000.005.063.613.761.70.062
and i want output
0.104
2.51
40.70
43.0
37.00
0.00
5.0
63.6
13.7
61.7
0.06
please help me to solve this.
|
|
|
|
|
So you're looking at positional indexing. In other words, get the string from position 0 to 4 then 5 to 8 and so on. The string class has many features that could make this life easier for you but, if I were you, I would look at the Substring[^] command.
This space for rent
|
|
|
|
|
What is the basis or pattern for the split? You example appears random.
Peter Leow
http://www.peterleowblog.com/
https://www.amazon.com/author/peterleow
|
|
|
|
|
string s = "0.1042.5140.7043.037.000.005.063.613.761.70.062";
List<int> widths = new List<int>() { 5, 4, 5, 4, 5, 4, 3, 4, 4, 4, 4 };
int index = 0;
widths.ForEach( w => { Console.WriteLine( s.Substring( index, w ) ); index += w; } );
|
|
|
|
|
thanks a lot substring work for me.
|
|
|
|
|
How to disable the keys while the system is in idle time ?
How to count the idle time of a user ?
|
|
|
|
|
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
So why would you want to disable the keyboard when the system is idle, given that the system will only become "busy" again in response to events - one of which is the user typing on the keyboard?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
There's a difference between an idle user and an idle system, and normal applications cannot disable all keys.
What are you trying to achieve?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Windows (API) mouse and keyboard hooks.
|
|
|
|
|
Ummm... why on earth would you disable a keyboard that isn't being used at the time?
|
|
|
|
|
|
I know that Func<t,tresult> is a delegate that takes T as a parameter and returns TResult as an output but I do not know what the following means.
Expression<Func<T, TResult>>
Can someone please explain what the above syntax means and how it is used.
modified 27-Dec-16 17:50pm.
|
|
|
|
|
|
Hi, thanks for replying. Your link does not help me understand what an Expression is in C# or how to use it.
I came across a method the other day and I was trying to find out what the syntax is trying do. I've been looking at tutorials on Expression on Youtube and Google but it didn't really help.
The following is the method I mentioned but I don't really know what it is supposed to do.
public IEnumerable<T> Find(Expression<Func<T, bool>> predicate)
{
return Context.Set<T>().Where(predicate);
}
modified 28-Dec-16 10:31am.
|
|
|
|