|
|
|
This is one of the uses of the Windows SetWindowPos function and is demonstrated with an annoying program that makes all open Notepad windows topmost for 10 seconds. That's just long enough to click on them a few times to confirm the modified behaviour before they revert to normal.
Alan.
using System;
using System.Diagnostics;
using System.Threading;
using System.Runtime.InteropServices;
namespace MakeTopMost {
internal sealed class App {
[Flags]
public enum SWP : uint {
NOSIZE = 0x0001,
NOMOVE = 0x0002,
NOZORDER = 0x0004,
NOREDRAW = 0x0008,
NOACTIVATE = 0x0010,
DRAWFRAME = 0x0020,
FRAMECHANGED = 0x0020,
SHOWWINDOW = 0x0040,
HIDEWINDOW = 0x0080,
NOCOPYBITS = 0x0100,
NOOWNERZORDER = 0x0200,
NOREPOSITION = 0x0200,
NOSENDCHANGING = 0x0400,
DEFERERASE = 0x2000,
ASYNCWINDOWPOS = 0x4000
}
public const Int32 HWND_TOPMOST = -1;
public const Int32 HWND_NOTOPMOST = -2;
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetWindowPos(
[In] IntPtr hWnd,
[In] IntPtr hWndInsertAfter,
Int32 X, Int32 Y, Int32 cx, Int32 cy,
SWP Flags);
internal static void Main() {
Process[] ps = Process.GetProcessesByName("notepad");
foreach (Process p in ps) {
Console.WriteLine("TopMost");
MakeTopMost(p.MainWindowHandle);
}
Thread.Sleep(10000);
foreach (Process p in ps) {
Console.WriteLine("Not TopMost");
RemoveTopMost(p.MainWindowHandle);
}
Console.WriteLine("...end");
Console.ReadLine();
}
private static void MakeTopMost(IntPtr targetHwnd) {
const SWP flags = SWP.NOSIZE | SWP.NOMOVE;
SetWindowPos(targetHwnd, (IntPtr)HWND_TOPMOST, 0, 0, 0, 0, flags);
}
private static void RemoveTopMost(IntPtr targetHwnd) {
const SWP flags = SWP.NOSIZE | SWP.NOMOVE;
SetWindowPos(targetHwnd, (IntPtr)HWND_NOTOPMOST, 0, 0, 0, 0, flags);
}
}
}
|
|
|
|
|
|
Colin,
In the following method is there something missing as I don't see how _hWnd1 is set.
private void StartOtherProcesses()
{
Process.Start(APP_1);
SetWindowPos(_hWnd1, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
}
Assuming there is some missing code, i.e. SetHwnd() , have you checked that the GetWindowsHandler method does actually get a non zero handle. Handle creation will be some time after process start and it not uncommon for Process.MainWindowHandle to be IntPtr.Zero for several hundred milliseconds even after Process.WaitForInputIdle() has returned (despite what MSDN says!).
By the way, I have verified by reading the extended style bits with GetWindowLong, that SetWindowPos will remove the WS_EX_TOPMOST style from a maximized topmost window.
Alan.
modified 3-Jul-12 21:00pm.
|
|
|
|
|
Alan N's solution is a very good one.
However, check if they have some modal / non-modal type if property which you can set in this control.
This will allow you to get away without writing sooo much more code.
|
|
|
|
|
Please. Can help.... I need to filter the color red, Green and yellow in a image contained in the control Emgu.CV.UI.ImageBox.
Please can guide as I detect any of the three colors (red, green, yellow).
filter using HSV
modified 2-Jul-12 16:36pm.
|
|
|
|
|
|
I have a form containing a DataGridView which I want to populate immediately upon creating the new form. The DataGridView is populated from a SQL query and I do it as follows:
using (SqlCommand mySqlCommand = new SqlCommand("SELECT * FROM MyTable", mySqlConnection))
{
using (SqlDataReader mySqlDataReader = sqlCommand.ExecuteReader())
{
DataSet myDataSet = new DataSet();
DataTable myDataTable = new DataTable();
myDataSet.Tables.Add(myDataTable);
myDataSet.Load(mySqlDataReader, LoadOption.PreserveChanges, myDataSet.Tables[0]);
myDataGridView.DataSource = myDataSet.Tables[0];
}
}
myDataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
foreach(DataGridViewRow myRow in myDataGridView.Rows)
Now, the above code works perfectly except for the last two lines of code, which automatically resizes each column to fit the widest cell and which iterates through the DataGridView and does something with some of the values. The reason this won't work is because, by the time they are executed, the databinding for the DataGridView might not yet be finished.
One solution is to add
myDataGridView.DataBindingComplete += new DataGridViewBindingCompleteEventHandler(myDataGridView_DataBindingComplete);
And then put those lines of code inside the event handler.
For various reasons, it happens from time to time that I'd rather have those lines of code inside the original function that populates the form. I'd be quite happy to enter a loop that will wait for the data binding to complete before I continue but I don't know how. Any suggestions?
|
|
|
|
|
Can't you just call the DataBind function explicitly?
like... myDataGridView.Databind();
Everything should be ready to go after that...
|
|
|
|
|
No, I believe that works only for Webforms, not for Winforms as is the case here.
I don't understand why that method is not available in winforms as it would have been the perfect solution for this problem of mine.
|
|
|
|
|
Hi, I need to edit the pdf using axAcroPdf component but, buttons used to edit are disabled. I cannot click on the buttons??? Thx.
|
|
|
|
|
Hey there, I'm sure there is some simple newbie problem with my code, but I have not been able to figure it out and was hoping another set of eyes would help.
I'm working on a financial accounting tool that so far has two tables, a Users table and an AccountsTransactions table, The below method is from my DatabaseCommunicator class. It builds fine but crashes with a message that the "Balance" column is not in the AccountsTransactions Table. Since I know that the column is in fact in the table, the only thing I can think of as being the problem is that I'm not actually connecting to the datasource and filling the dataset. Can anyone see where I'm going wrong?
Thanks in advance.
public string[] CreateNewTransaction(int UserID)
{
string[] returnArray = new string[2];
string selectSql = "SELECT Count(*) FROM AccountTransactions WHERE UserID = @UserID";
connect = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename='C:\\Users\\Ed\\Documents\\Visual Studio 2010\\Projects\\School Projects\\Accounts\\Accounts\\Accounts.mdf';Integrated Security=True;User Instance=True");
dataAdapter = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand(selectSql, connect);
dataAdapter.SelectCommand = cmd;
cmd.Parameters.AddWithValue("@UserID", UserID);
dataSet = new DataSet();
dataAdapter.Fill(dataSet, "AccountTransactions");
int lastRow = dataSet.Tables["AccountTransactions"].Rows.Count-1;
DataRow dRow = dataSet.Tables["AccountTransactions"].Rows[lastRow];
returnArray[0] = Convert.ToString(dataSet.Tables["AccountTransactions"].Rows[lastRow]["Balance"]);
returnArray[1] = Convert.ToString(dataSet.Tables["AccountTransactions"].Rows[lastRow]["TransactionNo"]);
connect.Dispose();
return returnArray;
}
|
|
|
|
|
deadEddie wrote: string selectSql = "SELECT Count(*) FROM AccountTransactions WHERE UserID = @UserID";
You are selecting column which are not present is select statement.
deadEddie wrote: returnArray[0] = Convert.ToString(dataSet.Tables["AccountTransactions"].Rows[lastRow]["Balance"]);
returnArray[1] = Convert.ToString(dataSet.Tables["AccountTransactions"].Rows[lastRow]["TransactionNo"]);
For accessing balance and transaction include them is select statement, like
Select Balance, TransactionNo FROM AccountTransactions WHERE UserID = @UserID;
|
|
|
|
|
Thanks Hum Dum. Of course that fixed my problem.
DE
|
|
|
|
|
It may help you .read it.
http://www.dapfor.com/en/net-suite/net-grid/tutorial
|
|
|
|
|
|
Hello guys, how can i do sock5 proxy for this ?
client = new TcpClient(host, port);
setClient(client);
|
|
|
|
|
Maybe this[^] could help you out.
|
|
|
|
|
no i didn't help
i need to connect a gameserver with different ips with 5 tcp clients.
|
|
|
|
|
I'm getting a very weird RuntimeBinderException that I cannot explain. I'm using .NET 4.0 and Workflow Foundation 4.0. The exception occurs when the workflow reaches an activity that uses the class that I assume is raising exception.
"The System.Datetime type cannot be implicitly converted to string".
The code never really reaches the method where the exception occurs (at least I assume it's this method as the console displays my own text that I write to the console in the catch block, though after changing the text it's the the old text I use) but rather seems to throw the exception before the method is actually called.
What's most confusing is that I don't really use any dynamics and made sure I don't implicitly convert a date to a string.
The System.Dynamics namespace is not used anywhere in the entire solution.
I use the SAP Business 1 RecordSet class, which has dynamics as fields, but this is the first time I get anything like this exception and I have been using them for months.
This is the code of the method: http://pastebin.com/FjxeXWB5[^]
This is the exception:http://i45.tinypic.com/mkhyde.png[^]
Thanks.
|
|
|
|
|
Somewhere a DateTime is being passed to a method that is expecting a string, and as it's not implicitly convertable to a string it is failing.
I would add break points in the code at every point where the DateTime instance is used and run until the culprit is found. It should then be easy to determine the problem and the resolution.
|
|
|
|
|
I am using SaveDialog to create a file by passing the FileName. I want to open the file after it's created / saved already. is there anyway to check if the file was completely created? because some files will take time (few more seconds) to get created and it will throw an error when I try to open immediatelly after save because the file was not yet created..
|
|
|
|
|
If I were writing this and I wanted to only open the file when it had finished writing, I would use a simple flag in the save routine and only reset it when the save finished. You could then put a simple test in your file open to only allow the file to be opened when it has finished writing.
|
|
|
|
|
Using the File.Exists method[^] should help you out.
With this you can check if the file exists at the specified path.
|
|
|
|
|