|
|
whenever i use
setstyle( ... ) ;
and in my paint function i do something like
void paintMethod( .., .. )
{
using( Graphics g = e.Graphics )
{
g.doesSomeDrawing();
}
}
the ... statements replace the actual code wich is corect
i am getting an error message saying "Additional information: Invalid parameter used."
and if i don't use the using statement everything works fine .. no error message !
Lazar Mihai
Elev clasa XI C
Grup Scolar Sanitar
|
|
|
|
|
I suspect it is the using
you are copying an existing Graphics object, not assigning a new one.
Gary
In Scotland, there is no such thing as bad weather - only the wrong clothes. - Billy Connolly
|
|
|
|
|
You can either not use the using statement, safely, or you can try something like this:
Graphics g = e.Graphics;
using ( g )
{
g.doesSomeDrawing();
}
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
The actual exception is because the caller of OnPaint (most often WndProc ) is trying to dispose the Graphics object and it's already been disposed.
He should not be using using at all.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I thought it might be something along those lines, wasn't sure though. Too drugged up to think about it and no VS.NET at work to test it with. 8( Let me tell you, life sucks without a compiler at fingertips!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I didn't have a compiler.
Basically, if you didn't alloc it then you don't free it. In native APIs this isn't always the case, though, since some APIs alloc memory and expect the caller to free it. Such APIs should always document such a requirement.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Heath Stewart wrote:
Basically, if you didn't alloc it then you don't free it. In native APIs this isn't always the case,
I've run into that many a time. I just wanted to try it before I stuck my foot in my mouth.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
The answer is simple. The using statement resolves to the following code:
try
{
g.doesSomeDrawing();
}
finally
{
g.Dispose();
}
U are disposing a graphics object that u dont "own" (e.graphics). On a general basis you should only dispose graphic objects that you explicitly create through the Control's CreateGraphics() method or through a New Graphics() statement;
|
|
|
|
|
Thanks.. I get it now.. U've all been of great help
Lazar Mihai
The road to becoming a good programmer is paved with bad scripts !
|
|
|
|
|
Hello,
I run the program below to handle winmessages from an application written in a 4GL. From within PaintExtras() I would like to call a function in the 4GL program to retrieve some properties (to be able to draw the icon on different positions f.e.). How can I do that? I can send the 4GL 's window-HWND to NotifyWindow in my C# program.
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication1
{
[ClassInterface(ClassInterfaceType.AutoDual)]
public class GenericWindow : NativeWindow
{
public const int WM_ERASEBKGND = 0x14;
public const int WM_DESTROY = 0x0002;
private const int GWL_WNDPROC = -4;
private const int WM_SYNCPAINT = 0x0088;
private const int WM_NCPAINT = 0x0085;
private const int WM_PAINT = 0x000F;
private IntPtr oldWndProc = IntPtr.Zero;
private Win32WndProc newWndProc = null;
private int hIcon;
#region Imported User32.DLL functions
[DllImport("user32.dll", CharSet=CharSet.Auto)]
static public extern int GetDC(int hWnd);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int ReleaseDC(int hWnd,int hDc);
[DllImport("User32.dll")]
private static extern int DestroyIcon(int hIcon);
[DllImport("user32.dll")]
public static extern int DrawIcon(int hdc, int x,int y, int hIcon);
[DllImport("user32.dll", EntryPoint="CallWindowProc")]
private static extern int CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImport("shell32.dll", CharSet=CharSet.Auto)]
public static extern int ExtractIcon(int hInst, string lpszExeFileName, int nIconIndex);
[DllImport("user32.dll")]
private static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, Win32WndProc newProc);
[DllImport("user32.dll")]
private static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex);
#endregion
// A delegate that matches Win32 WNDPROC:
private delegate int Win32WndProc(IntPtr hWnd, int Msg, int wParam, int lParam);
public GenericWindow()
{
}
public void NotifyWindow(int windowHandle)
{
this.AssignHandle((IntPtr)windowHandle);
oldWndProc = GetWindowLong((IntPtr)windowHandle,GWL_WNDPROC);
newWndProc = new Win32WndProc(MyWndProc);
SetWindowLong((IntPtr)windowHandle, GWL_WNDPROC,newWndProc);
PaintExtras();
}
private int MyWndProc(IntPtr hWnd, int Msg, int
wParam, int lParam)
{
int pHandle;
switch(Msg)
{
case WM_PAINT:
pHandle = CallWindowProc(oldWndProc, hWnd,Msg, wParam, lParam);
PaintExtras();
return pHandle;
case WM_DESTROY:
pHandle = CallWindowProc(oldWndProc, hWnd,Msg, wParam, lParam);
//MessageBox.Show("dest");
return pHandle;
default:
return CallWindowProc(oldWndProc, hWnd, Msg,
wParam, lParam);
}
}
public void PaintExtras()
{
int hdc = GetDC(this.Handle.ToInt32());
if (hdc != 0)
{
hIcon = ExtractIcon(this.Handle.ToInt32(),"C:\\progress10\\wrk\\experim\\down.ico",0);
int ret = DrawIcon (hdc, 1, 1, hIcon);
ret = DestroyIcon (hIcon);
ret = ReleaseDC(this.Handle.ToInt32(),hdc);
}
}
}
}
regards,
Stefan.
|
|
|
|
|
Hi,
I read from this tutorial at codeproject
Question A:
http://www.codeproject.com/csharp/GsXPathTutorial.asp
regarding xpath.. but i try to apply in my situation, and can't get it work...
just say this is my xml file:
Device.xml
=========
<?xml version="1.0" encoding="utf-8"?>
<DeviceList xmlns="http://tempuri.org/Device.xsd">
<!-- Device 1 -->
<Device id="1">
<Connection>
<Type>Titan123</Type>
<Open />
<ConfigCard>
<Name>Titan Suprema</Name>
<Length>13</Length>
</ConfigCard>
</Connection>
</Device>
<Device id="2">
<Connection>
<Type>BBB Hardware</Type>
<Open />
<ConfigCard>
<Name>BBB DH</Name>
<Length>6</Length>
</ConfigCard>
</Connection>
</Device>
</DeviceList>
In my C# code,
string devicePath = Application.StartupPath + @"\device.xml";
// open XmlTextReader
...
int nMaxId = 0;
// get maximum devices within XML script
while(xmlDevice.Read())
{
if (xmlDevice.IsStartElement() && xmlDevice.Name == "Device")
{
int nId = Int32.Parse(xmlDevice.GetAttribute("id"));
if (nMaxId < nId)
nMaxId = nId;
}
}
}
// Execute XPath here
XPathDocument xdoc = new XPathDocument(devicePath);
XPathNavigator nav = xdoc.CreateNavigator();
// loop into 2 possible devices and extract particular information
for (int i = 1; i < nMaxId + 1; i++)
{
XPathNodeIterator nodeItor = nav.Select(
"DeviceList/Device[@id='" + i + "']/Connection");
nodeItor.MoveNext();
TraverseChildren(nodeItor);
}
...
// from the article
private void TraverseChildren(XPathNodeIterator nodeItor)
{
XPathNodeIterator igor = nodeItor.Clone();
igor.Current.MoveToFirstChild();
bool more = false;
do
{
PrintNode(igor.Current);
more = igor.Current.MoveToNext();
}while(more);
}
private void PrintNode(XPathNavigator nav)
{
MessageBox.Show("Value: " + nav.Value +
" Type : " + nav.NodeType.ToString());
}
From this solution:
i get this instead:
MessageBox1 - Value: Titan123 Titan Suprema 13BBB Hardware BBB DH 6
MessageBox2 - Value: Titan123 Titan Suprema 13BBB Hardware BBB DH 6
(repeat the same message - why?)
Any help please?
I want to get the Output of this:
MessageBox1 - Value: Titan123 Titan Suprema 13
MessageBox2 - Value: BBB Hardware BBB H 6
Question B:
By the way how can i get the value of individual Type example,
showing the output here:
Type - Titan123
Name - Titan Suprema
Length - 13
i always only manage to get the type which is "Name" and the whole message "Titan123 Titan Suprema 13" instead separate data.
Any help please? Thanks.
Regards,
Chua Wen Ching
Visit us at http://www.necoders.com
|
|
|
|
|
If you have a question about an article here on this site, then use the message board at the bottom of the article. That's what the article-specific message boards are for.
http://www.codeproject.com/csharp/GsXPathTutorial.asp[^]
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hello
I want to make an application which will list down all the sites and directories present in IIS in C# application..i found code snippets for creation of site and Virtual Directories but didn`t find any example for viewing the hosted sites
is there anyway to achieve this goal?
Please Help me
-adnan
|
|
|
|
|
The APIs that those samples used are the very APIs (most likely) for enumerating virtual sites and directories. It's important to understand the scope and goal of the examples, not to simply copy and paste for the same functionality.
Since I don't know what examples you're talking about and since there's so many ways of creating, enumerating, and deleting virtual hosts and directories, I recommend using System.DirectoryServices to enumerate the iis:// namespace provider. See http://www.netomatix.com/EnumWebDirs.aspx[^] for an example.
This is the preferred way of accessing IIS information and is supported by many automation clients, including Windows Script (VBScript; JScript), Visual Basic 6 / VBA, and more. .NET supports this through the System.DirectoryServices namespace that I mentioned before.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks for reply,can you explain me about this syntax?
IIS://" + this.DomainName + "/W3SVC
i have oftened seem syntax like
IIS://" + this.DomainName + "/W3SVC/1
What`s the difference?
-adnan
|
|
|
|
|
If you search for "iis://" on http://msdn.microsoft.com/library[^] you can learn quite a bit about it.
this.DomainName is just what it sounds like - the domain name. Replace this with whatever computer you want to connect that is running IIS. The IIS Programmatic Administration Reference[^] - specifically for the IIS ADSI Provider[^] - descrbes that what comes after the computer name is the service to which you want to connect. "W3SVC" is the world-wide web (w3) service (svc). The number after that is the virtual host number (this is not necessarily serialized).
The first line enumerates all virtual hosts, while the second enumerates the first virtual host (or rather, the virtual host who's identifier is "1").
Read the links above for more information.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks i tried the code and it worked..however i want to know that is it possible to view all VirtualFolders and site at once?
i created a site in my IIS as "abc.com" and then i provided
path as IIS://abc.com/W3SVC/1/Root
but it gave RPC error
how can I do this?
Thanks
-adnan
|
|
|
|
|
If you read the documentation that I linked it explains how to enumerate all virtual sites. As I also mentioned, the site index (represented by the "1" in your URL above) is not a serial number and is seemingly random. This is why you must enumerate the sites first, then their services, then their applications and their directories, and so on.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
thanks for keep sending me replies..i was actually giving machine name as "localhost" though my Machine name is something else
one thing i didnt understand that what`s the different between "IISWebDirectory" and "IISVirualDirectory" i can understand Virtual directory which normaly is created under "localhost" website but what`s webdirectory?
-adnan
|
|
|
|
|
If you look at the documentation I link it should hopefully be clear. A virtual directory is a directory that doens't exist below the web root directory, but that was mapped into the web site. A web directory is a physical directory either under the web root or under a virtual directory (so a directory of the mapped directory, or one of the descendent directories).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks a lot
with the help of your kind guidance i have got some output..i can see all sites and their associated VDirs one by one..
-When I used the Syntax IIS://Machine/W3SVC it displayed the following O/p and ifound that some hiddenn "folders" like Info or Filters which normally i hadn`t seen in IIS, 1 ,2 and 3 were the sitesi created on my server..
C:\>IISDIRECTORI
Info=>IIsWebInfo
1=>IIsWebServer
Filters=>IIsFilters
2=>IIsWebServer
3=>IIsWebServer
ok now the issue is that even i close the server,i still get the result ,it don`t show Server close error or Exception message..how can I trace this?
Once again i am very much thankful of your kind help and I am sure i would achieve my goal..thanks
-adnan
|
|
|
|
|
IS it not possible to get the Site Description/site Name rather than these Numeric IDs?
-adnan
|
|
|
|
|
Hi all,
I want to retrieve objects from database by SQL. But if the matched
objects number size is huge (e.g. 1000 records), and I want to just get
40 result records for each fetch. How can I write the SQL to achieve this ?
(I don't want to write another SQL to project the first SQL results to 40 record)
Thanks
|
|
|
|
|