|
1. Set the PrintPreviewControl.Cursor property. This Cursor will only apply to the PrintPreviewControl . For the standard cursor set, see the Cursors class. If you only want the cursor to be different over the document (and not the "gray area" outside the document but within the PrintPreviewControl , you'll have to do the calculations yourself and handle the cursor display accordingly.
2. As I mentioned above, you really have to do the calculations yourself. There is nothing publicly exposed that helps you determine the exact logical dimensions of the document (there is for the physical size of the printed document), but you can make these calculations by using the Columns , Rows , and StartPage properties of the PrintPreviewControl . With a little trial and error, you should be able to use that information to construct and algorithm to get the document that was clicked.
3. Extend the PrintPreviewControl , override WndProc (be sure to call base.WndProc !) and handle the WM_HSCROLL (0x0114) and WM_VSCROLL (0x0115) windows messages. See the Platform SDK for more information about these two messages and what the WParam and LParam properties of the Message struct passed to WndProc will contain. You can find this information in the MSDN Library Online[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
public class Test
{
private int num1;
private int num2;
private int num3
[CategoryAttribute("BlackGround")]
public int Num1
{get{return num1;}
set{num1=value;}
}
[CategoryAttribute("BlackGround")]
public int Num2
{get{return num2;}
set{num2=value;}
}
[CategoryAttribute("ForeGround")]
public int Num3
{
get{return num3;}
set{num3=value;}
}
}
How get the Serialization result as below?
<test>
<blackground>
<num1>..
<num2>..
<foreground>
<num3>..
|
|
|
|
|
You only want to serialize properties based on the CategoryAttribute value? (BTW, in C# you don't need to include the ending "Attribute"; [Category("ForeGround")] will work just fine and makes for more readable code).
If you want more control over serialization, first attribute your class with [Serializable] and then implement the ISerializable interface. Read about the interface in the .NET Framework SDK for more information.
This gives you complete control over runtime serialization.
If you want to use XML Serialization, then you need to implement IXmlSerializable . This interface is, however, undocumented and not recommended for use (though you can use it - just be warned). It has three methods:
public interface IXmlSerializable
{
XmlSchema GetSchema();
void ReadXml(XmlReader reader);
void WriteXml(XmlWriter writer);
} It whould be pretty obvious what those methods do. Please note that this puts XML serialization completely in your hands. Any XML Serialization attributes you specify will not be used unless you use the information yourself in those method implementations.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
My app is very basic. It is a form that contains a panel. I initialize the panel to be the ClientSize of the form, and for it to be a square. I want it so that if the user chooses to resize the form, it will only allow him/her to do so while keeping the panel a square AND keeping it as the clientsize of the form (i.e. no gray space in the form). I've tried coding it so that the new size of the panel should be the min(user-chosen height, user-chosen width). Even so, I'm still having problems figuring out how to adjust the form's new size. Can anyone help? As of now, I'm only calling the Form1_resize eventhandler. Should I have a resize handler for the panel?
|
|
|
|
|
|
I want to create a print driver in C# that a user could print to and it would create a file on there computer. Is this possible? Does anyone know of an example that I could refer to? Thanks a lot.
|
|
|
|
|
Just to clarify, I want a user to be able to print to a printer that is set up to use this print driver and have it's output be a tiff image or whatever format I choose to implement. Would something like this be possible?
|
|
|
|
|
You can print to file.. using the normal windows printer functions.
But I don't know if that is what you're looking for.
"Every rule in a world of bits and bytes can be bend or eventually be broken"
|
|
|
|
|
No, because if I am not mistaken, print to file just sends the data stream that it would send to a printer to a file.
|
|
|
|
|
It's possible, but c# was not designed to do such low level work. Besides, I think what you want already exists. Install a new local printer, chose FILE: as the port, when you get to picking the printer driver, install Generic/Generic Text. Then you can output whatever you want. You'll have to output the file format yourself so you better know the exact format of a TIFF file or what ever your going to print.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Anyone have any experience/tips on how I'd go about setting up a database with stored procedures on my Pocket PC ( it's the 2003 OS ). I know there is a SQL Server CE, but it seemed to imply I didn't need to download it if I was using .NET languages. What's the alternative ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
|
Anders Molin wrote:
Whats wrong with SQL-Server CE?
I don't know. The point was that the Microsoft download page for SQL Server CE seemed to state it was not the way to go when developing for .NET. I've not even installed it yet, but the question is 'do I need to' ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Christian Graus wrote:
The point was that the Microsoft download page for SQL Server CE seemed to state it was not the way to go when developing for .NET.
Hmmm, interesting, I have to take a look at that.
I have mostly done CE development before .NET, but most of it is still the same
- Anders
Money talks, but all mine ever says is "Goodbye!"
ShotKeeper, my Photo Album / Organizer Application[^]
My Photos[^]
New developersite: RealDevs.Net
|
|
|
|
|
I've seen many examples on MSDN that use SQL Server CE, and the .NET Framework even has a SQL Server CE-specific ADO.NET provider. I'd say go with it; you most likely won't find a better CE database with that level of support from .NET.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'm still trying to get this SetupDiGetDeviceInterfaceDetail function to work in C#.
I am using these definitions now:
[StructLayout(LayoutKind.Sequential)]
public class SP_DEVICE_INTERFACE_DATA
{
public uint cbSize;
public Guid InterfaceClassGuid;
public uint Flags;
public IntPtr Reserved;
}
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
public class SP_DEVICE_INTERFACE_DETAIL_DATA
{
public uint cbSize;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=1)]
public string DevicePath;
}
[StructLayout(LayoutKind.Sequential)]
public class SP_DEVINFO_DATA
{
public uint cbSize;
public Guid ClassGuid;
public uint DevInst;
public IntPtr Reserved;
}
[DllImport("setupapi.dll")]
public static extern bool SetupDiGetDeviceInterfaceDetail(
IntPtr DeviceInfoSet,
ref SP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
out SP_DEVICE_INTERFACE_DETAIL_DATA DeviceInterfaceDetailData,
uint DeviceInterfaceDetailDataSize,
out uint RequiredSize,
out SP_DEVINFO_DATA DeviceInfoData);
Ok, the MSDN Library tells me this:
Using the SetupDiGetDeviceInterfaceDetail function to get details about an interface is typically a two-step process:
1. Get the required buffer size. Call SetupDiGetDeviceInterfaceDetail with a NULL DeviceInterfaceDetailData pointer, a DeviceInterfaceDetailDataSize of zero, and a valid RequiredSize parameter. In response to such a call, this function fails, GetLastError returns ERROR_INSUFFICIENT_BUFFER, and the RequiredSize parameter receives the required buffer size.
2. Allocate an appropriately sized buffer and call the function again to get the interface details.
The interface details returned by this function include a device path that can be passed to functions such as CreateFile. Do not attempt to parse the device path symbolic name. Note that the device path can be reused after the system is rebooted.
The SetupDiGetDeviceInterfaceDetail function can be used to get only the DeviceInfoData parameter. If the interface exists but the DeviceInterfaceDetailData parameter is NULL, the function fails, GetLastError returns ERROR_INSUFFICIENT_BUFFER, and the DeviceInfoData structure is filled with information about the device that exposes the interface.
Now this is what I am doing:
Win32APIfunctions.SP_DEVICE_INTERFACE_DATA devInterfaceData = new Interfaces.Win32APIfunctions.SP_DEVICE_INTERFACE_DATA();
devInterfaceData.cbSize = (uint)Marshal.SizeOf(devInterfaceData);
Win32APIfunctions.SP_DEVICE_INTERFACE_DETAIL_DATA devInterfaceDetailData = null;
Win32APIfunctions.SP_DEVINFO_DATA devInfoData = null;
uint uiRequiredSize=0;
Win32APIfunctions.SetupDiGetDeviceInterfaceDetail(NewDeviceInfoSet, ref devInterfaceData, out devInterfaceDetailData, 0, out uiRequiredSize, out devInfoData);
int iLastError = Marshal.GetLastWin32Error();
I always get errorcode 1421 ERROR_CONTROL_ID_NOT_FOUND.
It's driving my mad! Everything looks correct to me
-------------------------------------------
The light at the end of the tunnel has been switched off temporarily due to budget problems...
|
|
|
|
|
Pain_Elemental wrote:
Win32APIfunctions.SetupDiGetDeviceInterfaceDetail(NewDeviceInfoSet, ref devInterfaceData, out devInterfaceDetailData, 0, out uiRequiredSize, out devInfoData); int iLastError = Marshal.GetLastWin32Error();
Why are you checking for the last error, if you dont even know if there is one!? Test the return value of the call. That could be dirty data, or maybe you reading the number wrong...
top secret xacc-ide 0.0.1
|
|
|
|
|
Well, the only return value of interest is uiRequiredSize, but this is always 0.
By the way, I always check for last error just for debugging perpose.
-------------------------------------------
The light at the end of the tunnel has been switched off temporarily due to budget problems...
|
|
|
|
|
I forgot to set SetLastError=true at the import statement.
Now I get an other error code.
Here's my piece of code again:
Win32APIfunctions.SP_DEVICE_INTERFACE_DATA devInterfaceData = new Interfaces.Win32APIfunctions.SP_DEVICE_INTERFACE_DATA();
devInterfaceData.cbSize = (uint)Marshal.SizeOf(devInterfaceData);
Win32APIfunctions.SP_DEVICE_INTERFACE_DETAIL_DATA devInterfaceDetailData = null;
Win32APIfunctions.SP_DEVINFO_DATA devInfoData = null;
uint uiRequiredSize=0;
if(!Win32APIfunctions.SetupDiGetDeviceInterfaceDetail(NewDeviceInfoSet, ref devInterfaceData, out devInterfaceDetailData, 0, out uiRequiredSize, out devInfoData))
{
int iLastError = Marshal.GetLastWin32Error();
Win32Exception myEx = new Win32Exception();
throw new System.ApplicationException(myEx.Message, myEx.InnerException);
}
Now I get
Error code: 1784
ERROR_INVALID_USER_BUFFER: The supplied user buffer is not valid for the requested operation.
I think that possibly this could be the problem:
Win32APIfunctions.SP_DEVICE_INTERFACE_DATA devInterfaceData = new Interfaces.Win32APIfunctions.SP_DEVICE_INTERFACE_DATA();
devInterfaceData.cbSize = (uint)Marshal.SizeOf(devInterfaceData);
Am I allowed to cast to uint here?
-------------------------------------------
The light at the end of the tunnel has been switched off temporarily due to budget problems...
|
|
|
|
|
I use a PictureBox array in my project;
<br />
public PictureBox[] illustration;<br />
illustration = new PictureBox[10];<br />
...<br />
myInkPicture[IntSelectPage].illustration[i] = new System.Windows.Forms.PictureBox();<br />
...<br />
myInkPicture[IntSelectPage].illustration[i].MouseDown += new System.Windows.Forms.MouseEventHandler(myInkPicture[IntSelectPage].illustration_MouseDown);<br />
the ten PictureBoxes use the same MouseDown event handler,
<br />
public void illustration_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)<br />
{<br />
pictureBox1.Capture = true;<br />
startMoveLocation = new Point(e.X, e.Y); <br />
}<br />
I want the pictureBox1 to be the illustration[i] ,
How can I typecast the object sender to be the illustration[i] PictureBox...??
|
|
|
|
|
Hi,
In your mouse down event handler sender is the object that caused the event. In this case it will be whatever picturebox the mouse went down over. I believe that by casting sender to a picturebox you will have the picturebox that the mouse went down on aka illustration[i].
Do this with ((PictureBox)sender).Capture = true;
Karl
|
|
|
|
|
I have tried and it really works !!
Thank you very much
|
|
|
|
|
Ok guys, I've done my research and I have found great articles here that really gave me a kickstart on updating the UI by calling Invoke on the main thread from a worker thread. But I'm trying to apply this knowledge to an application which uses delegates to perform asynchronous calls without sucess. Here is the interesting situation:
I have a delegate declared outside the windows form class resposible for the UI updates
public delegate void delegateUpdateStatus(string msg);
then there is the delegate which I use for the asynchronous calls (inside the form class)
public delegate void delegateAsynch(parameters here);
in the click event of a button I create an instance of the asynchronous delegate
delegateAsynch myAsynchDelegate = new delegateAsynch(target function)
then I use the BeginInvoke method on the asynchronous delegate and works perfectly great. Now I have decided to update the UI with a label giving feedback of the progress. That's where the first delegate declared above comes in. The problem is that in the target function I make a call to Invoke like:
Invoke(new delegateUpdateStatus(updateStatus), new object[] {"Hello"});
or BeginInvoke(new delegateUpdateStatus(updateStatus), new object[] {"Hello"});
and the application goes to a zombie state with any of those statements without even modifying the UI (I tried only one of those statements on different runs). I have carefully placed breakpoints to see where it is hanging but after any of those lines is executed no other instruction is called, not even the method (updateStatus) the delegate is supposed to call. It is worth noting that Intellisense really knows that Invoke or BeginInvoke comes from Control. I have slapped against a wall, please help!
|
|
|
|
|
Make sure you check Control.InvokeRequired before calling Control.Invoke or Control.BeginInvoke to determine if invoking is even necessary. If it is not required, just call updateStatus directly. Since yo're using async invocation, it should be required but it was just a thought. I do this quite a bit in our enterprise app and have never had a problem.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank you Stewart for your reply. After reading your post I put the call to the update delagate in an if statement with the condition lblStatus.InvokeRequired . To my surprise the InvokeRequired property always returned false. How can this be if before using asynchronous delegates the UI freezed. Now that I'm using async invocations the UI is responsive as it should be. Also, a direct call to the updateStatus method does not update the UI, although the program does not enter a zombie state. Any ideas!? The fact that the lblStatus.InvokeRequired returned false got me confused with async invocation using delegates.
|
|
|
|