|
I was wondering if you could have a public structure with private/public objects within it? Like in this example
<br />
public struct ClientData<br />
{<br />
public Socket clientSocket;<br />
public Thread clientThread;<br />
private int clientMonitorID;<br />
}
or if you define it as public does object within become public
Yes, I program in VB6, but only because I use it to fill my addiction to having a dry place to sleep and food to eat!
|
|
|
|
|
Yes you can have a public structure with private and public objects in it.
The private objects will not be accessible from outside the struct, this can be used if for example you want to pass a value to the constructor of the struct and use it internally (do not want other objects to access it).
public struct ClientData
{
private int clientMonitorID;
public ClientData(int clientMonitorID)
{
this.clientMonitorID = clientMonitorID;
}
public int FunctionX()
{
FunctionX = clientMonitorID + 1
}
}
Edbert P.
Sydney, Australia.
|
|
|
|
|
Yes, as Elbert said, it is possible. I wanted to add that, like classes, you should actually declare public properties that reflect private fields in your structure. This not only gives you a chance to validate input (always a good idea) but also to invoke delegates if necessary since properties are just getter and/or setter methods. You can still do it with fields, but it's quite a bit more difficult.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I was wondering. Is there an easy way to dock a windows form? i have a scroller that I would like to place at the top or bottom of my desktop. I want it to dock so all the other windows resize to accomidate it. I know you can dock buttons inside the form with the dock property. I tried this.dock = DockStyle.Top; but it seems to have no effect on the windows form. Any suggestions would be great.
Win32newb
"Programming is like sex, make one mistake and you have to support it for a long time"
|
|
|
|
|
The best way is to create an AppBar - just like the Windows Task Bar and the old Office Shortcut Bar. See the article C# does Shell, Part 3[^] here on CodeProject.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I need to convert various datatypes (mostly doubles, bytes and strings) to byte array and then read it back. I need to read it the fastest way possible and it will be read thousands of times and written only once.
What I use now is BinaryReader/Writer like so:
MemoryStream stream = new MemoryStream()
BinaryWriter writer = new BinaryWriter(stream)
.. loop ..
writer.write(byte)
writer.write(double)
writer.write(string)
...
return stream.ToArray();
I don't care how fast writing is.
Then I need to read the data:
byte[] data = ...
MemoryStream stream = new MemoryStream(data);
BinaryReader reader = new BinaryReader(stream);
while (stream.Position < stream.Length)
{
byte b = reader.ReadByte();
switch (b)
{
// depending on value of b read strings, doubles or bytes
}
}
This approach doesn't seem to be too fast. I'm wondering if there is a faster way to do that.
Thanks.
|
|
|
|
|
See the BitConverter class documentation in the .NET Framework SDK.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Dear forum members,
An object of a managed class (written in C#) is passed to the
clipboard during drag&drop operation. The object has to be
dropped on to a MFC view (written in VC++ .Net).
How do I create/access my object from the COleDataObject
which I get while 'Droping' into a view ?
Is there any other way to do this ?
[Hope I have explained my problem well ...]
Thanks in advance.
svkr.
|
|
|
|
|
This gets into marshaling. You can't just send a managed object through the clipboard (unless you exposed it as a CCW, or COM-Callable Wrapper) and used the interface re-declared (with the necessary GUID, or IID) in unmanaged code. The easiest way is to marshal the object so that it has a well-known representation, whether thats the fields packed into a byte[] array or whatever. You can also use the Marshal class to assist with this.
Those are really the only two ways to do this and marshaling would probably be the best way since it doesn't rely on COM and exposing your object (and all child objects that you must access) as CCWs.
Marshaling also means you can drag and drop your managed object to something that doesn't provide COM programming but instead abstracts drag and drop and provides you the data. With a well-known structure, you can marshal the data back to a representative object. One example would be a scripting language like JScript or VBScript. While you could expose your object as a automation-compatible (i.e., IDispatch implementation) CCW, this requires some knowledge of automation types and automation itself.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
In the first post i changed my initials from WVR into my name (Wouter Van Ranst), wich is the possible cause for the site-system for not recognising me as the signed-in user...
|
|
|
|
|
I want to develop custom DataGrid control to trap enter key and make it work like tab key within DataGrid web control using C#. Any help is greatly appreciated.
Thanks
|
|
|
|
|
This has been covered before in this forum. A quick search[^] would've turned up a few previous posts.
You don't need to develop a custom DataGrid . In fact, the DataGrid has nothing to do with it. It's the DataGridTextBoxColumn whose behavior must be changed. You must handle the TextBox 's key events and send a TAB instead of ENTER. This can lead to problems with committing the changes in the TextBox to the underlying data source as well. See the search results for details.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'm adding other customization to it also. But you are assuming that the grid is going to have only text box, what about combo box? Do you have any sample article or code
|
|
|
|
|
Again, this has little to do with the DataGrid itself. What you need is derivatives of the DataGridColumnStyle , which means you must explicitly add DataGridTableStyle s to the DataGrid.TableStyles collection property (see the documentation for more information). You can define table styles for multiple tables only once. The table style that matches up to a particular table (or typed array) will be used according to the DataGridTableStyle.MappingName property documentation in the .NET Framework SDK.
If you want a combo box, there is plenty of examples that have been discussed in this forum and are available both on this site and elsewhere on the Internet. There is a pretty good example on MSDN[^]. Just search.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Well after searching in so many places, I decided to ask the in discussion board. Anyway can you point to any article or sample which specifically shows how to make enter key work as tab key within Datagrid web control? I don't want any reference here and there
Thanks,
|
|
|
|
|
Why don't you try the ASP.NET[^] forum, where this should've been posted in the first place, then.
The [Enter] key is handled by the browser and you can't override like you can with Windows Forms. HTML is not a rich environment and using custom field styles works much differently.
Besides, I'm not just going to hand over the answer. This is to help you learn. If you want code samples you can rip off without learning anything, try open source sites with full source code like http://www.sourceforge.net[^] or http://www.gotdotnet.com[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Why not use the keypress event and then change the ascii code from [enter] to [tab]? Pretty sure this will work.
[edit] Heath and I must have grabbed this at the same time. But Heath was a little more in depth than I.
I won't dignify your question with an answer. Yes, I program in VB6, but only because I'm addicted to eating!
|
|
|
|
|
Is there a keypress event for datagrid web controls column template?
|
|
|
|
|
Is anyone know how or where I can get information about LZW compression
using C#?
Thank You
bettie
|
|
|
|
|
|
Hi, guys. I have a slightly related question about compression. I've been banging out some code that uses the Imaging namespace's EncoderParameters to save an image as a multipage TIF. My problem is that the default compression schema appears to be LZW; or, at least, that is what some of my property readers are telling me. Anyway, I'm trying to save a multipage TIF with CCIT Group 4 Compression, but I get "invalid paramter" exception any time I try to add compression parameters.
Heath, do you have any experience with saving multipage TIFs with CCIT Group 4 compression in GDI+? If not, do you know anyone who does?
I can post my code, if you're interested.
|
|
|
|
|
In order to use a different encoding, there must be an encoder installed and registered with GDI and/or GDI+ to be used. This is done by passing the Guid of the encoder to the Encoding class, which you use with an EncodingParameter , which gets added to an EncodingParameters collection you pass when using Image.Save .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Can I show you my code? It is just one console file.
|
|
|
|
|
What would it help? The fact remains that an encoder for the compression you're trying to use must be installed correctly on your system. You can use Encoder.Compression to create an Encoder . You can then use the EncoderValue to specify the compression you want to use. If you look at the documentation for the Encoder.Compression read-only, static property in the .NET Framework SDK, you'll even see an example of using a certain compression algorithm to save a TIFF.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I know that I have the encoder installed on my machine because I can save single pages at G4 as well as multi-page tifs with the default compression, but I run into issues when I put the two together. My sample code reads a TIF file name from the app.config file, saves the first page in the file as a G4 image, saves the whole document as multipage file, but then fails when using the G4 EncoderParameter along with the save MultiFrame parameter. I'm using the same algorithm each time, just passing in addition EncoderParameters to the method.
The astrices show the problem:
using System;<br />
using System.Drawing;<br />
using System.Drawing.Imaging;<br />
using System.IO;<br />
<br />
namespace consoletest<br />
{<br />
class Class1<br />
{<br />
[STAThread]<br />
static void Main(string[] args)<br />
{ <br />
string testName = System.Configuration.ConfigurationSettings.AppSettings["testName"];<br />
string compName = "compressed.tif";<br />
string multiName = "multi.tif";<br />
string multiG4 = "multiG4.tif";<br />
<br />
System.Drawing.Image original = Bitmap.FromFile( testName ); <br />
<br />
try<br />
{ <br />
Image[] pages = Class1.ToImageArray( original );<br />
Class1.ToGroup4Compressed( pages[1], compName ); <br />
Class1.ToMultiPageImage( pages, multiName );<br />
Class1.ToMultiPageImage( pages, multiG4, Class1.GetGroup4Parameter() );<br />
}<br />
catch( Exception e )<br />
{ <br />
System.Diagnostics.Debug.WriteLine( e );<br />
}<br />
}<br />
<br />
public static Image[] ToImageArray( Image image )<br />
{<br />
int count = image.GetFrameCount( System.Drawing.Imaging.FrameDimension.Page );<br />
Image[] images = new Image[ count ];<br />
<br />
if( count > 1 )<br />
{<br />
for( int i = 0; i < count; i++ )<br />
{<br />
image.SelectActiveFrame( System.Drawing.Imaging.FrameDimension.Page, i ); <br />
images[ i ] = image.Clone() as Image;<br />
}<br />
}<br />
<br />
return images;<br />
}<br />
<br />
public static void ToGroup4Compressed( Image image, string fileName )<br />
{<br />
ImageCodecInfo info = GetCodec( "image/tiff" );<br />
Encoder enc = Encoder.Compression;<br />
EncoderParameters ep = new EncoderParameters();<br />
ep.Param[0] = new EncoderParameter( enc, (long) EncoderValue.CompressionCCITT4 );<br />
image.Save( fileName, info, ep );<br />
}<br />
<br />
public static Image ToMultiPageImage( Image[] pages, string fileName, params EncoderParameter[] p )<br />
{ <br />
Image image = new Bitmap( pages[0] ); <br />
FileStream stream = new FileStream( fileName, FileMode.OpenOrCreate );<br />
<br />
Encoder enc = Encoder.SaveFlag; <br />
ImageCodecInfo info = GetCodec( "image/tiff" );<br />
EncoderParameters ep = new EncoderParameters( p.Length + 1 ); <br />
ep.Param[0] = new EncoderParameter( enc, (long) EncoderValue.MultiFrame );<br />
<br />
int index = 1;<br />
foreach( EncoderParameter param in p )<br />
ep.Param[ index++ ] = param;<br />
<br />
image.Save( stream, info, ep );<br />
ep.Param[0] = new EncoderParameter( enc, (long) EncoderValue.FrameDimensionPage );<br />
for( int i = 1; i < pages.Length; i++ )<br />
image.SaveAdd( pages[ i ], ep );<br />
ep.Param[0] = new EncoderParameter( enc, (long) EncoderValue.Flush );<br />
image.SaveAdd(ep);<br />
<br />
stream.Close();<br />
return image;<br />
}<br />
<br />
public static EncoderParameter GetGroup4Parameter()<br />
{ <br />
return new EncoderParameter( Encoder.Compression, (long) EncoderValue.CompressionCCITT4 );<br />
} <br />
<br />
public static ImageCodecInfo GetCodec( string mimeType )<br />
{<br />
foreach( ImageCodecInfo ice in ImageCodecInfo.GetImageEncoders() )<br />
if( ice.MimeType.Equals( mimeType ) )<br />
return ice;<br />
<br />
throw new Exception( mimeType + " mime type not found in ImageCodecInfo" );<br />
}<br />
}<br />
}
|
|
|
|