|
Or escape the tags themselves using < for < and > for > .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
i kown,bu i don't know why the xml tag became disappeared!
ok
|
|
|
|
|
Hello, i wanted to know if anybody knows of a good reference to study the TCP/IP protocol programming with C#, the way you structure packets, compression/decompression etc.
|
|
|
|
|
|
I'm creating a button that opens a popup window when clicked, to display further options. I locate the topleft corner of the control at same location as button itself, by using mybutton.PointToScreen. No problem.
When the button is too close to the bottom of screen I locate the popup at location
mybutton.PointToScreen.Y - popup.Height + mybutton.height (i.e. open it upwards instead of downwards in a sence...)
This all works fine, if I use normal fonts. However when using larger font size in windows it becomes a problem for me.
the code looks like this:
<br />
Popup popup = new Popup();<br />
<br />
Rectangle screenBounds = Screen.GetBounds(this.Location);<br />
<br />
float scaleY = Form.GetAutoScaleSize(this.Font).Height / 13.0f;<br />
float scaleX = Form.GetAutoScaleSize(this.Font).Width / 5.0f;<br />
<br />
Point ButtonLocation = ((Control)sender).PointToScreen(Point.Empty);<br />
int x = ButtonLocation.X;<br />
int y = ButtonLocation.Y;<br />
<br />
if( screenBounds.Bottom < (y+popup.Height) )
{<br />
if( eventButtonLocation.Y < popup.Height )<br />
popup.Height = eventButtonLocation.Y; <br />
<br />
y = (eventButtonLocation.Y - popup.Height + eventLabel.Height);<br />
}<br />
<br />
if(screenBounds.Right < (x + popup.Width) )
x = x - popup.Width + ((Control)sender).Width;<br />
<br />
popup.Location = new Point(x,y);<br />
<br />
popup.Closed += PopupClosedEventHandler;<br />
<br />
popup.Show();<br />
now what happens internally is that the popup window is scaled using the Control.Scale()
method, since I have the AutoScale property of the popup form set to true.
This won't take effect until the call to Show() however, which means that my control
will be misplaced cause it will also scale the location of the form.
I can calculate the desired location after the call to the Show() method,
but this will first bring up the popup in the wrong location and
THEN move it, and the whole thing won't look very good...
Any ideas? I've tried to use the calculated scaleX and scaleY values to account for the
scaling done by the System, but can't quite get it right. The scale values I calculate
are the exact same the system uses, that I've concluded through testing. So I should be able
to fix it...
Can anyone help me? Or maybe give me a good briefing of how exactly the autoscale works? What I could
find out from the documentation is that the scaling should be performed in the constructor but that
is not the case from what i've found out (displaying a message before the constructor, after the constructor,
and inside an overridden scalecore() method in the popup (which is called from the Scale method)
the scale message shows up last, i.e. long after the constructor has finished.
|
|
|
|
|
Control.Scale is public - simply try calling it before performing your operations that require the scaled properties.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
It will be a great help if i get answers to the following problems related customized PrintPreviewDialog that I have prepared using PrintPreview Control :
1.When the mouse is moved over PrintPreviewControl, how to change the cursor only when it is on the document that is displayed in the control? It should remain at default state outside the document. Or how the get the dimensions of the document displayed in PrinPreviewControl?
2.When two pages are displayed in the PrintPreviewControl, how to identify which page is clicked?
3. How to display the vertical scroll bar of PrintPreviewControl programatically?
can we sense its up/down click events? such that it can be used for Next/Previous page movement.
Please guide
|
|
|
|
|
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...
|
|
|
|