|
Thank you very much for your article. It's very helpful for me.
Asura
|
|
|
|
|
Glad to be of service. If you have questions, feel free to email me. Writing custom controls is a hobby of mine, and I'm glad to give out tips and tricks.
|
|
|
|
|
Jon Rista is right. You can use winform controls like textboxes for creating your own controls. Just create a child class from the textbox class and add your custom events and members to your class.
|
|
|
|
|
Oh, actually, I spaced out subclassing. You can also derive a class from an existing control, nad augment/add to its functionality, like Heinz said. I still recomment starting with UserControls, but subclasses controls are a good intermediate step between UserControls and full custom controls.
|
|
|
|
|
Hi,
I've done a drag and drop of a sqlDataAdapter and generated a dataset on a second WinForm (Form2) I'm opening as a dialog box. I can bind to it and retrieve results but I get an error when I try to use any BindingContext.Count/Position methods on the dataset. Any help greatly appreciated.
Error: 'Cannot create a child list for field myTable.'
Code Snippet Follows:=======================================
try
{
int iCnt;
iCnt = this.BindingContext[this.dsExtPhyLookup1, "tblExternalPhysicians"].Count;
}
catch(Exception exp)
{
MessageBox.Show(exp.Message.ToString());
}
|
|
|
|
|
hi all,
i need to pass a record between forms. i got it working for now, but i don't think it's right.
1st. form has a read only datagrid bound to a dataset.
2nd. on double-click event, i'm currently looping through col values
3rd. send individual col values to new form.
i don't think this is right (and yes, i'm a newbie) cause if i'm using locale then the value in the col on the grid would be a converted value and not necessarily the value in the dataset right?
how can i pass the record from the dataset to a form (best practice) use a structure?
tia
|
|
|
|
|
I assume you want to transfer the data of the current row or something similar.
One apporach would be to fill a structure or little helper class which you can pass around. Another idea would be to transfer the whole DataRow object (DataTable.Rows[currentRowIndex]).
|
|
|
|
|
excellent, i started down the structure path. thanks for such a quick response!
|
|
|
|
|
I'm trying to read numbers from a TextBox and convert them. Even though I have
a number in the TextBox the compiler can't convert. Which got me thinking about the above question....thanks
|
|
|
|
|
Convert.ToInt32(string value) internally calls Int32.Parse(string s) so it doesn't matter which one you call.
What makes you think it doesn't work? Are you probably trying something like Convert.ToInt32(textbox) instead of Convert.ToInt32(textbox.Text)? Or is the string probably not fitting into an integer?
|
|
|
|
|
toint32 takes 1 arguement
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemConvertClassToInt32Topic13.asp
parse takes 2
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemInt32ClassParseTopic3.asp
i might be missing something, but couldn't you also trap the keypress event and verify your numeric's there?
if(char.IsNumber(e.KeyChar) == false)
e.Handled = true;
|
|
|
|
|
HI all
I need to write two C# program ,
The first one is like a server and second one is the client [both program are in the local Host computer].
In C++ i wrote something like it in COM+ (ATL) and the two program had connecting throw this com.
But in C# i don't how to define my 2 different project to have those connection.
Can someone help me ?
Thanks
|
|
|
|
|
|
Hello gurus,
Given a color, I'd like to know how to calculate the nearest color from the standard list?
For example:
given the color: FFD3D3D3, the function will return FFD7D7D7 which is Color.LightGray
Color clr=new Color(0xd3, 0xd3, 0xd3);<br />
Color nearestColor=GetNearestColor(clr);
will return Color.LightGray to nearestColor
Can anybody help me to solve this?
Thanks in advance.
Best regards.
Fred.
There is no spoon.
|
|
|
|
|
|
I have a project where I need to create a windows .exe by compiling code and linking in some resources. This program thats being generated is somewhat unconventional, and I'll explain how. I'm generating a very simple installer app that embeds referenced .dll files inside it, which are extracted and referenced when the installer app is executed. This works great when the installer app is built with Visual Studio .NET, but it does not work when I compile it myself using a CSharpCodeProvider. The resources are written to a .resource file using a ResourceWriter just prior to compilation of the .exe. I add a custom compiler option to embed the resources. Code follows:
PopupProgress.Display("Compiling Installer...", null, "Compiling", "Creating
compiler...", 3, 1);
// Create code compiler
CSharpCodeProvider provider = new CSharpCodeProvider();
ICodeCompiler compiler = provider.CreateCompiler();
// Create compiler parameters
PopupProgress.Display("Compiling Installer...", null, "Compiling",
"Configuring compiler...", 3, 2);
CompilerParameters cparams = new CompilerParameters();
cparams.Evidence = new
System.Security.Policy.Evidence(AppDomain.CurrentDomain.Evidence);
cparams.GenerateExecutable = true;
cparams.GenerateInMemory = false;
cparams.IncludeDebugInformation = false;
//cparams.MainClass = "S2CIPInstaller.Main";
//cparams.OutputAssembly = step4.CompileTarget;
cparams.TempFiles = new TempFileCollection(m_basePath + @"temp\", true);
cparams.ReferencedAssemblies.Add("System.dll");
cparams.ReferencedAssemblies.Add("System.Drawing.dll");
cparams.ReferencedAssemblies.Add("System.Windows.Forms.dll");
// cparams.ReferencedAssemblies.Add("System.XML.dll");
cparams.ReferencedAssemblies.Add(m_basePath +
@"temp\SynapticEffect.Collections.dll");
cparams.ReferencedAssemblies.Add(m_basePath + @"temp\DatGen.DBPF.dll");
cparams.CompilerOptions = "/resource:\"" + m_basePath +
"temp\\S2CIPInstaller.resources\"";
//cparams.Win32Resource = m_basePath + @"temp\S2CIPInstaller.resources";
// Compile
PopupProgress.Display("Compiling Installer...", null, "Compiling", "Please wait...", 3, 3);
CompilerResults results = compiler.CompileAssemblyFromSource(cparams, code);
PopupProgress.Remove();
int errCount = 0;
for (int i=0; i<results.errors.count; i++)
{
="" if="" (!results.errors[i].iswarning)
="" errcount++;
}
if="" (errcount=""> 0)
{
MessageBox.Show(this, "There were errors during compilation. Installer not created.");
}
else
{
MessageBox.Show(this, "Installer successfully created!");
}
When I use the code provider from my own program, I get the following error (only visible after attaching with a debugger. I apologize for the coded .exe name --> yodjgmq_.exe):
An unhandled exception of type 'System.Resources.MissingManifestResourceException' occurred in mscorlib.dll
Additional information: Could not find any resources appropriate for the
specified culture (or the neutral culture) in the given assembly. Make sure "S2CIPInstaller.resources" was correctly embedded or linked into assembly "yodjgmq_". baseName: S2CIPInstaller locationInfo: DatGen.S2CIPInstaller resource file name: S2CIPInstaller.resources assembly: yodjgmq_, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
Does anyone know why the installer app works when compiled with VS.NET, but not with the CSharpCodeProvider and ResourceWriter classes from the .NET Framework from my own code? Any insight is greatly appreciated.
Jon Rista
jrista@hotmail.com
|
|
|
|
|
I'm kind of desperate at this point. I've done everything I can to get my compiled program to work, but it keeps telling me hte resources are missing, even though hex-editing the .exe shows it there.
|
|
|
|
|
Help!!!
I am trying to create black and white images of screen shots I have captured from the desktop.
I am able to do everything other than produce black and white images.
I can create colour images but our FileNet IDM viewer cannot cope with the type of tiff file created.
So, how do I create a black and white image from the desktop colour image?
The code I am using only gives me the option to select colour image formats. e.g. Below uses PixelFormat.Format16bppRgb555.
HOW CAN I GET A BLACK AND WHITE IMAGE FROM THE BITMAP?
Any help gratefully received.
Bitmap bmPhoto = new Bitmap(imageWidth, imageHeight, PixelFormat.Format16bppRgb555);
bmPhoto.SetResolution(img.HorizontalResolution, img.VerticalResolution);
Graphics grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic;
grPhoto.DrawImage(img, new Rectangle(0, 0, imageWidth, imageHeight), new Rectangle(0, 0, img.Width, img.Height), GraphicsUnit.Pixel);
grPhoto.Dispose();
GC.Collect();
Colin.
|
|
|
|
|
You would have to operate on each pixel, and set the color for each component (except alpha) to the average of R,G,B. You can do this with GetPixel/SetPixel, but its extremely slow. Using pointers in unsafe code is faster by several magnitudes:
// For 32bit image
public unsafe void ReduceToGrayscale(Bitmap bmp)
{
PixelFormat pf = PixelFormat.Format32bppArgb;
GraphicsUnit unit = GraphicsUnit.Pixel;
RectangleF rf = m_bitmap.GetBounds(ref unit);
Rectangle r = Rectangle.FromLTRB((int)rf.Left, (int)rf.Top, (int)rf.Right, (int)rf.Bottom);
// OR: Rectangle r = Rectangle.Round(rf);
BitmapData bd = bmp.LockBits(r, ImageLockMode.ReadWrite, pf);
byte* pixel = (byte*)bd.Scan0;
byte r, g, b, avg;
for (int y=0; y<bd.width; y++)
="" {
="" for="" (int="" x="0;" x<bd.height;="" x++)
="" b="*(pixel);
" g="*(pixel+1);
" r="*(pixel+2);
" agv="(r+b+g)/3;
" *(pixel)="avg;
" *(pixel+1)="avg;
" *(pixel+2)="avg;
" *(pixel+3)="0xFF;" alpha
="" pixel="" +="4;
" }
="" }
="" bmp.unlockbits(bd);
}
this="" code="" works="" a="" 32bit="" image.="" 16bit="" image,="" you="" will="" have="" to="" take="" into="" account="" the="" stride="" length.="" bitmap="" image="" in="" .net,="" every="" always="" uses="" enough="" memory="" full="" mage,="" even="" if="" its="" just="" 8bit="" indexed.="" so,="" of="" 555,="" each="" is="" only="" going="" be="" half-full.="" also,="" colors="" are="" diced="" up="" from="" 2="" bytes,="" rather="" than="" 4.="" so="" might="" do="" something="" like="" this="" your="" inner="" loop:
short*="" curcolor;
byte="" r,="" g,="" b,="" avg;
="" ...
curcolor="*(pixel);
b" =="" (curcolor="" &="" 0x1f);
g="((curColor">>5) & 0x1F);
r = ((curColor>>10) & 0x1F);
a = ((curColor>>15) & 0x1);
// Expand color components to 8bit, then average here.
// Several ways to do this, more complicated than I
// can write in a couple minutes.
r = g = b = avg;
a = 1;
// Reduce color components to 5bit...
curColor = 0;
curColor = (short)((a<<15) & (r<<10) & (g<<5) & (b));
*(pixel) = curColor;
pixel++;
Using pointers like this is significantly faster than using GetPixel/SetPixel, and its pretty strait forward code (You'll need to look up the reduction/expansion code for converting 16bit 555 color to 32bit color. There are plenty of resources on the internet with the info. I'd write it myself, but I have limited time.) Hope this helps, and I hope it was Grayscale you were after. Reduction to true B/W (two color, not 256 shades of gray) is a bit more complicated.
|
|
|
|
|
Hello all,
Thanx to all replyers.
I trying to figure out how to use these wonderful DirectShow Demo projects on this site to create a converter from 32bit color depth to 16 bit in C#.
Is it possible?
I`ve learned that graphBuilder2 will always fix the graph as he wants.
Can someone help with a graph code that converts 32bit video to 16bit color depth?.
Many thanx.
|
|
|
|
|
(I'm using C# 2.0)
Hi,
I have placed an icon file in resources.resx. The problem is that I don't know how to retrieve it.
In VB.NET 2.0, My.Resources.MyIcon does the trick, but what's the C# equivalent? Unfortunately, what happens under the hood with the My namespace is not well documented. Reflector on Microsoft.VisualBasic.dll didn't help either.
Can anyone help me on this? Here's my code:
protected System.Drawing.Icon GetIcon()
{
Assembly a = Assembly.GetCallingAssembly();
Stream stream = null;
Icon icon = null;
try
{
stream = a.GetManifestResourceStream("MyIcon.ico");
icon = new Icon(stream);
return icon;
}
catch {
return null;
|
|
|
|
|
Well, there are two kinds of resources for a .NET project. There are manifest resources, and compiled resources. A manifest resource is something you would include in your project, like a .ico file, and mark as "Embedded Resource". That marks the resource as being directly embedded into the .NET programs manifest.
There are also resources that are compiled into a single resource file, and that file is then embedded into the .exe. Your <filename>.resx file, under your form, is not the actual resource file. If you have a form, Form1.cs, that form also has a Form1.resx file. All resources for the form are stored in the .resx file. When you compile your project, that resx file is converted into a .resources file (look in your .\obj\ folder to find it after compile). The final step in compilation is to link or embed a .resources file into the .exe. Its also possible to create other .resx files, each of which will be compiled and embedded into the .exe when you compile the project.
Manifest resources can be accessed using the code you posted, but resources from a .resx file are different. You can not access them directly from the assembly, and must use a ResourceManager to do the job. Check out the System.Resources namespace (I think its the same for .NET 2.0 as for 1.1), and learn how to use the ResourceManager, ResourceSet, and ResourceReader classes. Using those, you should be able to access the resources that were generated from your resources.resx file.
|
|
|
|
|
This is the simplest way to retrieve resources from a linked resource if you are using neutral culture.
This example shows you how to retrieve strings, icons & images (any bin file can be retrieved), this example asumes that you have strings, icons & images in your resource file:
using System.Drawing;
using System.Resources;
using System.Reflection;
class MyClass
{
private ResourceManager rm = new ResourceManager "MyResourcefilenamewithnoextension",Assembly.GetExecutingAssembly());
public string GetString(string key)
{
return rm.GetString(key);
}
public Icon GetIcon(string key)
{
return (Icon)rm.GetObject("MyIcon.ico");
}
public Image GetImage(string key)
{
return (Image)rm.GetObject("MyImage.png");
}
}
Hope this little code helps you.
|
|
|
|
|
This code was very helpful, thank you!
|
|
|
|
|
There're type errors and the forum doesn't allow me to modify the post:
1) a "(" is missing when creating an instance of ResourceManager.
2) In method GetImage "MyImage.png" should be key.
3) In method GetIcon "MyIcon.ico" should be key.
I'm glad to help.
|
|
|
|
|