|
Err...Heath...I think he was talking about the PropertyGrid control. When you have certain classes selected, there's this little section added to the bottom of it with links. His particular example was the DataAdapter class. If you drag one onto your form, and then click on it in the components tray, and view its properties, then you'll see links at the bottom like "Configure Data Adapter" or "Generate DataSet".
youd ebtter bnot be taki8ng agvantage o f my mental abilites!1
-David Wulff one night over MSN while totally plastered
|
|
|
|
|
In that case, derive from the appropriate ComponentDesigner and override the Verbs property to return a collection of DesignerVerb objects (see documentation in .NET Framework SDK for more information about these classes - it's really pretty straight-forward).
Finally, attribute your component with the DesignerAttribute attribute, passing the Type of your designer from above to the constructor of the attribute.
For more information, see Enhancing Design-Time Support[^] in the .NET Framework.
Sorry for the confusion - it's late.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I have a form with a few controls on it. The controls cover the whole area of the form.
I have a function that is executed when clicking on a treeview.
This function takes a few seconds to execute, where it talks to a database and does some painting in one of the controls.
At the top of that function I call
Cursor.Current = Cursors.WaitCursor;
and at the end iI call
Cursor.Current = Cursors.Default;
But... The cursor only blinks with the hourglass, then its back to normal, while the computer is working...
[edit]
Do I really have to loop through all the components in the form, setting the cursor on each one?
Naaa, I hope not...
[/edit]
Any ideas?
- Anders
Money talks, but all mine ever says is "Goodbye!"
My Photos[^]
|
|
|
|
|
If you execute the statement to fill the tree in a separate thread, the current cursor will be set to the default immediately since the method you called executes in another thread. If you call Application.DoEvents in your code before wanting the default cursor to be reset, if will be set to Cursors.Default , so don't call Application.DoEvents , either.
Finally, make sure you have something like the following: it's all too often that wait cursors are left showing when a process has finished in err:
Cursor current = Cursor.Current;
try
{
Cursor.Current = Cursors.WaitCursor;
}
finally
{
Cursor.Current = current;
} Optionally, you can forget about storing the current cursor (for instance, if you know your method is in the only thread of execution running, such as the main UI thread) and just use Cursors.Default .
But you don't have to set this on every control. Cursor.Current set the wait cursor and stops processing mouse events for the entire application. Only Control.Cursor sets the desired cursor for just that control.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I'm not filling the treeview, I'm using the treeview selection to fetch data from a database, and show a lot of photo thumbnails in another control using GDI+.
I tried something fun. At the top of the function I sat the treeview cursor to an hourglass, and never sat it back to normal, I also removed the calls to Cursor.Current.
When I move my mouse over the treeview i get an hourglass as expected (the function have executed when the app loaded), but when I change the selection, I get the arrow cursor when processing and the hourglass when finished working.
This really don't make any sense to me, and I really think it sucks that when I set cursor.current, the system just sets it back to default when the thread is going idle (like waiting for a database or the filesystem). At least it looks that way to me.
Mmmm, sometime I whish I had done this app in C++ and Win32 instead, at least I did not have those stupid problems there
It took somewhat more time to make GUI stuff, but not all those stupid problems...
- Anders
Money talks, but all mine ever says is "Goodbye!"
My Photos[^]
|
|
|
|
|
The application can't be idle if the UI thread is currently executing code, such as "waiting" for database results or reading a file. An idle state of an application indicates that the STA on which the application was started is not currently processing. So, something else is reseting your cursor. The only other way to process queued notification messages on the UI thread is to call Application.DoEvents as I mentioned above.
If you want the cursor to be the WaitCursor for the whole app, make sure you use Cursor.Current and not the Cursor property of the control. Since the control also contains a Cursor property, use System.Windows.Forms.Cursor to specify the class just to be sure.
As far as this vs. Win32, all this wraps the functions defined in the Win32 APIs. Much - it not most - of the Framework does encapsulate the Win32 APIs.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath Stewart wrote:
The application can't be idle if the UI thread is currently executing code, such as "waiting" for database results or reading a file.
A thread get idle when waiting for a database ot reading a file. It have always been that way, trust me
And... I don't call Application.DoEvents() anywhere what so ever in my application, but the cursur still automatically changes to an arrow.
Heath Stewart wrote:
If you want the cursor to be the WaitCursor for the whole app, make sure you use Cursor.Current and not the Cursor property of the control.
Yes, I do know that, I just dont think you know why I wrote as I did
It was just for testing, you know, and I found it funny that when the application was processing stuff, it changed the hurglass cursor to an arrow.
Thanks for your attempt to help but I guess you dont know whats happening, no more than I do...
It's probably just another quirck of the .NET framework.
Heath Stewart wrote:
As far as this vs. Win32, all this wraps the functions defined in the Win32 APIs. Much - it not most - of the Framework does encapsulate the Win32 APIs.
Yes, but have you ever used the Win32 API with C++?
So much more control.
- Anders
Money talks, but all mine ever says is "Goodbye!"
My Photos[^]
|
|
|
|
|
Our application makes an extraordinary amount of database calls, even through remoting and never goes idle, hence we never have a problem with the wait cursor resetting. These calls are typically made in the STA thread. The only time I have had problems with the wait cursor resetting is when I make asynchronous calls.
Anders Molin wrote:
Yes, but have you ever used the Win32 API with C++?
Since Windows 3.1. Still do, although most development is in a couple .NET languages, mostly C#.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
A thread that waits for something is idle, and the cpu does other things in the mean time
Well, I think we think of "idle" as different things...
- Anders
Money talks, but all mine ever says is "Goodbye!"
My Photos[^]
|
|
|
|
|
Heath,
I'm sure you know this, but it's good to show everyone the preferred way to work with Wait Cursors in C#:
using (Cursor.Current = Cursors.WaitCursor)
{
}
Regards,
Alvaro
"I do" is both the shortest and the longest sentence in the English language.
|
|
|
|
|
Hello fellow code poets,
I am attempting to sign an assenbly with a strong name the VS.NET way using the KeyFileAttribute in the AssemblyInfo.cs file.
I have read over MS documentation in the Framework SDK, Knowledgebase and the commented instructions in the AssemblyInfo.cs.
And of course all three sources show you something a little different.
This is the basics of my error:
http://support.microsoft.com/default.aspx?scid=kb;en-us;328379&Product=sql2k
I have tried to use these three examples I was given and they have all failed.
[assembly: AssemblyKeyFile(@"..\\..\\tempKey.snk")]
[assembly:AssemblyKeyFileAttribute("tempKey.snk")]
[assembly: AssemblyKeyFile("..\\..\\tempKey.snk")]
I have placed the key in the project directory, Visual Studio Projects/Project directory and in the bin and I am still failing it seems to get the right location.
Can any one help?
Thanks.
Jarrad D.
|
|
|
|
|
Make sure you have generated a key and put it in the projects directory using
sn.exe -k KeyFile.snk Keep this file safe and do not share it.
Also, when using the literal specifier "@", do not escape your backslashes like you are in the first example. The location of the file is relative to the build path. VS.NET builds everything relative to bin\(Debug|Release) by default, so your first and third examples are correct (assuming the key pair file is generated correctly). The third will not work unless building your project from the project directory (possible using the csc.exe command-line compiler).
Just as a side note, it doesn't matter where you put assembly attributes, so long as they're part of a source file being compiled into your assembly.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks for the help Heath.
The tempKey.snk is my key and I have tried all my examples having put my key in the bin\ it still will not compile without the errror.
Any other ideas?
Thanks.
Jarrad
|
|
|
|
|
The bigger question was about how it was generated. Did you use "sn.exe -k filename"? It has to contain at least the private key. "-k" will generate a key pair, which contains the public and private key.
Also, what exactly is the exception you're getting? Specifics are always more helpful.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
In my first post I linked to a MS KB article that contains the compile error I am receiving.
"Cryptographic failure while signing assembly '...\WindowsApplication1.exe' -'Error reading key file 'key.snk' -- The system cannot find the file specified."
I did use the -k when creating my key.
Thanks again.
Jarrad
|
|
|
|
|
Just to isolate if the problem is with the file, or with the file location, try to put the full file path ("c:\\project\\blablabla\\tempKey.snk").
Trying to make bits uncopyable is like trying to make water not wet.
-- Bruce Schneier
By the way, dog_spawn isn't a nickname - it is my name with an underscore instead of a space. -- dog_spawn
|
|
|
|
|
Daniel,
It was with literal location. I got it to work. Is it normal to use ("c:\\project\\blablabla\\tempKey.snk")? In the examples it made it sound like this ex. [assembly: AssemblyKeyFile("..\\..\\tempKey.snk")] was what told the compiler to look for it in the bin.
Anyway thanks.
|
|
|
|
|
No, this tells the compiler to look for it in the second parent directory above the build directory, which is bin\Debug or bin\Release. That means that "..\\..\\" is the directory with the project file (.csproj, for a C# project, for example).
If you can, it's often better to use a relative path so that you don't have to worry about where you copy the project directory to and having to keep the same structure (which is especially important when managing the code using a version control system like Visual SourceSafe or CVS.
The directory structure should look like this if you use "..\\..\\KeyFile.snk" in your [assembly: AssemblyKeyFileAttribute] :
Project Directory
+-bin
| +-Debug
| | +-MyApp.exe
| | +-MyApp.pdb
| +-Release
| +-MyApp.exe
+-AssemblyInfo.cs
+-Form1.cs
+-KeyFile.snk
+-MyApp.csproj
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks again for all the great information.
You guys have been very helpful.
Hope I can return the favor sometime.
|
|
|
|
|
Hello,
I managed to use several network Windows API inside C# code with DllImport (such as GetAdaptersInfo) but the GetIfTable seems to be a little bit different.
My problem is that i need to obtain the data in the MIB_IFROW structure and it gets filled with zeros instead of the corect information.
Here is the source code of a simple console application where the problem occurs:
<br />
using System;<br />
using System.Runtime.InteropServices;<br />
using System.Runtime;<br />
<br />
namespace ConsoleApplication1<br />
{<br />
public class Win32Import<br />
{<br />
public static uint ERROR_NOT_SUPPORTED = 50;<br />
<br />
public const int MAXLEN_IFDESCR = 256;<br />
public const int MAXLEN_PHYSADDR = 8;<br />
<br />
public const int MAX_INTERFACE_NAME_LEN = 256;<br />
<br />
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]<br />
public struct MIB_IFTABLE<br />
{<br />
public uint dwNumEntries;<br />
public MIB_IFROW table;<br />
};<br />
<br />
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]<br />
public struct MIB_IFROW<br />
{<br />
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_INTERFACE_NAME_LEN)]<br />
public string wszName;<br />
<br />
public uint dwIndex;<br />
public uint dwType;<br />
public uint dwMtu;<br />
public uint dwSpeed;<br />
public uint dwPhysAddrLen;<br />
<br />
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAXLEN_PHYSADDR)]<br />
public byte[] bPhysAddr;<br />
<br />
public uint dwAdminStatus;<br />
public uint dwOperStatus;<br />
public uint dwLastChange;<br />
public uint dwInOctets;<br />
public uint dwInUcastPkts;<br />
public uint dwInNUcastPkts;<br />
public uint dwInDiscards;<br />
public uint dwInErrors;<br />
public uint dwInUnknownProtos;<br />
public uint dwOutOctets;<br />
public uint dwOutUcastPkts;<br />
public uint dwOutNUcastPkts;<br />
public uint dwOutDiscards;<br />
public uint dwOutErrors;<br />
public uint dwOutQLen;<br />
public uint dwDescrLen;<br />
<br />
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAXLEN_IFDESCR)]<br />
public byte[] bDescr;<br />
};<br />
<br />
<br />
[DllImport("kernel32.dll", EntryPoint = "CopyMemory")] public extern static void<br />
CopyMemory_Int(<br />
ref uint Destination,<br />
ref byte Source,<br />
int Length<br />
);<br />
<br />
[DllImport("kernel32.dll", EntryPoint = "CopyMemory")] public extern static void<br />
CopyMemory_MibIfrow(<br />
ref MIB_IFROW Destination,<br />
ref byte Source,<br />
int Length<br />
);<br />
<br />
[DllImport("iphlpapi.dll")] public extern static uint<br />
GetIfTable(<br />
byte[] pIfTable,<br />
ref uint pdwSize,<br />
bool bOrder<br />
);<br />
}<br />
<br />
<br />
class Class1<br />
{<br />
[STAThread]<br />
static void Main(string[] args)<br />
{<br />
uint nBufLen = 0;<br />
uint nError;<br />
<br />
nError = Win32Import.GetIfTable(null, ref nBufLen, true);<br />
if (nError == Win32Import.ERROR_NOT_SUPPORTED)<br />
{<br />
return;<br />
}<br />
<br />
byte[] IfTableBuffer = new byte[nBufLen];<br />
nError = Win32Import.GetIfTable(IfTableBuffer, ref nBufLen, true);<br />
if (nError != 0)<br />
{<br />
return;<br />
}<br />
<br />
uint dwNumEntries = 0;<br />
int byteCount = 0;<br />
<br />
Win32Import.CopyMemory_Int(ref dwNumEntries, ref IfTableBuffer[byteCount], 4);<br />
byteCount += 4;<br />
<br />
Win32Import.MIB_IFROW pIfRow = new Win32Import.MIB_IFROW();<br />
Win32Import.CopyMemory_MibIfrow(<br />
ref pIfRow,<br />
ref IfTableBuffer[byteCount],<br />
Marshal.SizeOf(pIfRow)<br />
);<br />
byteCount += Marshal.SizeOf(pIfRow);<br />
}<br />
}<br />
}<br />
If you are familiar with these C# API calls and think you can help me , you're welcome. Many thanks!
|
|
|
|
|
First, use the out keyword instead of ref in the first parameter of GetIfTable to avoid having to instantiate the structure. Not a big deal, but it is the correct declaration.
Also, you're MIB_IFROW structure is incorrect. First, the first string member is a WCHAR - a wide character (2 bytes). Therefore, your CharSet in the StructLayoutAttribute should be set to CharSet.Unicode . The UnmanagedType.ByValTStr will then cause the marshaler to use what the CharSet in the StructLayoutAttribute declares, namely a Unicode string (an array of WCHAR s).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
It works!
I didn't thought that this mistake would be the reason of the problems.
But it's logic as Unicode and ANSI characters don't have the same size.
Thank you very much!
|
|
|
|
|
I'm using a MonthCalendar control in a C# winforms application and have discovered that if you click the text above the calendar which displays the year, two scroll buttons appear to allow you to scroll through the years. The up button scrolls into the future and a new date is selected as each year is scrolled. The down button scrolls back in time, but instead of selecting a single new date, a date range is selected. Does anyone know of a method/property that can be adjusted to turn off this behaviour for the down scroll button? Thanks.
Chris Meech
We're more like a hobbiest in a Home Depot drooling at all the shiny power tools, rather than a craftsman that makes the chair to an exacting level of comfort by measuring the customer's butt. Marc Clifton
VB is like a toolbox, in the hands of a craftsman, you can end up with some amazing stuff, but without the skills to use it right you end up with Homer Simpson's attempt at building a barbeque or his attempt at a Spice rack. Michael P. Butler
|
|
|
|
|
If you don't want a range of dates to be selectable at all, set MonthCalendar.MaxSelectionCount to 1. If you only want a single date selected while changing dates, you could handle the MonthCalendar.DateChanged and select only the MonthCalendar.SelectionStart date.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath Stewart wrote:
set MonthCalendar.MaxSelectionCount to 1.
I have the property set to a value of 1 already. I expect that this is a subtle bug I've stumbled across. The odd part is that for two seemingly similar actions, year/scroll-up or year/scroll-down, the control behaves differently.
Chris Meech
We're more like a hobbiest in a Home Depot drooling at all the shiny power tools, rather than a craftsman that makes the chair to an exacting level of comfort by measuring the customer's butt. Marc Clifton
VB is like a toolbox, in the hands of a craftsman, you can end up with some amazing stuff, but without the skills to use it right you end up with Homer Simpson's attempt at building a barbeque or his attempt at a Spice rack. Michael P. Butler
|
|
|
|
|