|
Waaaaaaaaaaahhhh
Have the same problem, to lazy to research and test code.
Please help the weaklings and the lazy ones...
Thank you very much for your help
|
|
|
|
|
hi all,
i would like to write C# code that would allow a user to upload images to a file on a remote server any ideas or solutions for me pleez. this would require ftp access and i am uncertain how i am going to integrate this into the app. the idea is the to upload new images when the need arises...
many thanks
butchzn
|
|
|
|
|
Uploading files greatly depends on what the server protocol is. If you're using HTTP, for example, the HttpWebRequest already supports this. Since you're requiring FTP, realize that the current .NET BCL has no FTP support - but don't let that stop you.
Some articles on this site and others have simply wrapped the ftp.exe application in a class library. This is dodgy and not very well designed. A proper design - like HttpWebRequest and HttpWebResponse - would extend WebRequest and WebResponse , classes for pluggable protocols.
It just so happens that there's a good example in the Microsoft Knowledge Base: http://support.microsoft.com/default.aspx?scid=kb%3BEN-US%3B812409[^]. It has a link at the bottom to GotDotNet (a Microsoft developer community site) with the full source.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Is there a simple way to paint in a colour inverse to the current image?
(I'm implementing a mouse-drag selection box, and want to just draw a rectangle on screen where each pixel is the inverse of whatever's already there)
--
Help me! I'm turning into a grapefruit!
|
|
|
|
|
The inverse colors are easy to calculate. Subtract the red, green, or blue (RGB) component from 255:
Color Invert(Color c)
{
int r = 255 - c.R;
int g = 255 - c.G;
int b = 255 - c.B;
return Color.FromArgb((int)c.A, r, g, b);
} But there's a easier way, and it's a little faster since the Color structure stores the ARGB (alpha, red, green, blue) as a single 64-bit number (though most members reflect a 32-bit number):
Color Invert(Color c)
{
Color c2 = Color.FromArgb(0xffffff - c.ToArgb());
return Color.FromArgb((int)c.A, c2);
} All this is assuming you keep the same alpha value, which is typically want you want to do.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
|
Microsoft, I noticed, doesn't use a lot of unsigned types, even when private or internal (since unsigned types are not CLS-compliant, but for private and internal members I don't see why it matters). If they used a signed int , solid black would be -1, something that may pose a problem for those using reflection. Maybe Microsoft plans on supporting CMYK along with an alpha channel in the future (requiring more than 32 bits).
It's all just speculation, though. I really don't know.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Thanks, I was figuring I was going to have to do something like that - but was hoping I'd just be able to set my pen colour to some magic constant that'd tell the gdi functions to draw in an inversed colour
--
Help me! I'm turning into a grapefruit!
|
|
|
|
|
I'm programming a GUI in C# with the objective to interface with a program written in C++ (MS-DOS). The MS-DOS program reads some information from a text file and then writes the results to a binary file. Depending on the initial information, the program can run for several hours and write large information to the binary file.
For now I can read the text file, write the information to several windows in the GUI, run the MS-DOS program in the background, retrieve the results in real time as the program runs and show it to the user (in real time).
What I want to ask is there any other way to communicate between the C++ program and the C# GUI?
Thanks in advance for any answers.
Filipe Delgado
|
|
|
|
|
Yes, but define "C++". Are you talking about managed or "unmanaged" (formerly just known as C++) C++? If you're speaking of unmanaged C++, then you're stuck with the ways of doing it between two native applications. That includes DDE, RPC, and the like - all of thich are not supported in the current .NET releases (IPC is supported in .NET 2.0 - at least last time I checked). If you want to some IPC mechanism you'll have to P/Invoke the necessary functions or find a library that already does it (there are a couple here on CodeProject; just search).
The other option is an oldie but a goodie: HWND s. The use of FindWindow , FindWindowEx , SendMessage , PostMessage , and the like is supported because Windows Forms encapsulates the Windows APIs (among other APIs, like GDI in some cases). Most of the controls (sans DataGrid ) encapsulates the Windows Common Controls, and every control - by nature on Windows - is tied to an HWND .
Using Spy++ can help you realize the classes used by the controls, although you'll find most use the same classes as the Common Controls because they are the same window classes.
This has been discussed here on this forum before, and there are articles about this on CodeProject. A quick search should find you the answers you need if you don't have them already.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Heath Stewart wrote:
Are you talking about managed or "unmanaged" (formerly just known as C++) C++?
Grrr. When people say C++, surely they mean proper C++, not this 'managed' crap.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
You're preaching to the choir. However, this is the C# forum - a managed language - so the distinction between native (is that better ?) and managed C++ is necessary.
In as many cases as possible, I refer to it only as "C++".
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Hi everyone,
I've been stuck with this problem for several days already. My code extensively uses asynchronous delegate invocation using the Delegate.BeginInvoke method. The general pattern is as follows:
Scheduler or UI thread:
1) BeginInvoke function 1
First function:
1) prepare data
2) BeginInvoke data processing passing CurrentThread (see below)
3) CurrentThread.Suspend
4) (after resume) go to step 1 with new data processing command, if all commands are executed, exit
Data processing:
0) get calling thread (passed in parameters)
1) process data
2) set result
3) resume calling thread
Several data processing commands (Command pattern) require asynchronous calls, too. That is that BeginInvoke method is called from inside another method which was called using BeginInvoke, too. What I've noticed so far is that sometimes the delegate being BeginInvoke'd is NOT CALLED AT ALL! To give more evidence, I have a special Logger class which sends messages to a text box. Apparently, it uses Control.BeginInvoke to correctly dispatch Text property changes. Sometimes again the function specified in MethodInvoker delegate is also NOT CALLED AT ALL!
What could be the problem? I honestly hope it is not a bug in the framework, as the project is (and has been for the last month) in the final stage.
Regards,
Serge (Logic Software, Easy Projects .NET site)
|
|
|
|
|
hello guys
i have a problems with the following code but i can't identify any on having idea please help me
the problems are:
1 when activate and deactivate it doesn't paint NCArea
2 it flickers
3 it doesn't give the feel like windows default title
//NCButton class
using System;
namespace WindowsApplication1
{
///
/// Summary description for NCButton.
///
public class NCButton
{
System.Drawing.Image nBitmap,fBitmap,pBitmap;
System.Drawing.Rectangle buttonRectangle;
public NCButton()
{
//
// TODO: Add constructor logic here
//
nBitmap = null;
fBitmap = null;
pBitmap = null;
}
public System.Drawing.Image NormalButtonImage
{
get
{
return nBitmap;
}
set
{
nBitmap = value;
}
}
public System.Drawing.Image FocusedButtonImage
{
get
{
return fBitmap;
}
set
{
fBitmap = value;
}
}
public System.Drawing.Image PressedButtonImage
{
get
{
return pBitmap;
}
set
{
pBitmap = value;
}
}
public System.Drawing.Rectangle ButtonRectangle
{
get
{
return buttonRectangle;
}
set
{
buttonRectangle = value;
}
}
}
}
//form1 class
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
namespace WindowsApplication1
{
///
/// Summary description for Form1.
///
///
public class Form1 : System.Windows.Forms.Form
{
private System.ComponentModel.IContainer components;
///
/// Required designer variable.
///
///
private ArrayList ncButtons;
[Category("Custom Mouse Events")]
private event System.Windows.Forms.MouseEventHandler NonClientMouseMove;
private event System.Windows.Forms.MouseEventHandler NonClientMouseDown;
private event System.Windows.Forms.MouseEventHandler NonClientMouseUp;
System.Drawing.Bitmap imgTitle,imgLRBorder,imgBBorder,imgButtons;
Rectangle bt1,bt2,bt3;
private System.Windows.Forms.ImageList imageList1;
private System.Drawing.Graphics graphics;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
ncButtons = new ArrayList();
NCButton bt = new NCButton();
bt.FocusedButtonImage = new Bitmap(@"C:\btimages\fmin.bmp");
bt.NormalButtonImage = new Bitmap(@"C:\btimages\nmin.bmp");
bt.PressedButtonImage = new Bitmap(@"C:\btimages\pmin.bmp");
Rectangle rect = new Rectangle(0,0,bt.NormalButtonImage.Width,bt.NormalButtonImage.Height);
bt.ButtonRectangle = rect;
ncButtons.Add(bt);
bt = new NCButton();
bt.FocusedButtonImage = new Bitmap(@"C:\btimages\fmax.bmp");
bt.NormalButtonImage = new Bitmap(@"C:\btimages\nmax.bmp");
bt.PressedButtonImage = new Bitmap(@"C:\btimages\pmax.bmp");
rect = new Rectangle(0,0,bt.NormalButtonImage.Width,bt.NormalButtonImage.Height);
bt.ButtonRectangle = rect;
ncButtons.Add(bt);
bt = new NCButton();
bt.FocusedButtonImage = new Bitmap(@"C:\btimages\fclose.bmp");
bt.NormalButtonImage = new Bitmap(@"C:\btimages\nclose.bmp");
bt.PressedButtonImage = new Bitmap(@"C:\btimages\pclose.bmp");
rect = new Rectangle(0,0,bt.NormalButtonImage.Width,bt.NormalButtonImage.Height);
bt.ButtonRectangle = rect;
ncButtons.Add(bt);
imgTitle = new Bitmap(@"C:\Skin Images\title.bmp");
imgLRBorder = new System.Drawing.Bitmap(@"C:\Skin Images\LRF.bmp");
imgBBorder = new System.Drawing.Bitmap(@"C:\Skin Images\BottomF.bmp");
imgButtons = new System.Drawing.Bitmap(@"C:\Skin Images\Button.bmp");
//graphics = new System.Drawing.Graphics();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
protected override void WndProc(ref Message m)
{
if(m.Msg == 0x1)//once when application starts
{
}
else if(m.Msg == 0x85 || m.Msg == 0x86)//nc_paint //nc_activate
{
IntPtr regn = m.WParam;
IntPtr hdc = Form1.GetDCEx(m.HWnd,regn,0x1 | 0x30);
if(hdc != IntPtr.Zero)
{
graphics = Graphics.FromHdc(hdc);
}
RepaintTheNCArea();
}
else if(m.Msg == 0xA0 )//nc mouse move
{
if( MouseMoveHandling(FindMousePosition()))
return;
}
else if(m.Msg == 0xA1 )//nc mouse button down
{
if( MouseDownHandling(FindMousePosition()) )
return;
}
else if(m.Msg == 0xA2 )//nc mouse button up
{
if (MouseUpHandling(FindMousePosition()))
return;
}
label1.Text = m.Msg.ToString();
base.WndProc (ref m);
}
[DllImport("User32.DLL", EntryPoint="GetDCEx", SetLastError=true,
CharSet=CharSet.Ansi, ExactSpelling=true,
CallingConvention=CallingConvention.Winapi)]
public static extern IntPtr GetDCEx(
IntPtr hWnd, // handle to window
IntPtr hrgnClip, // handle to clipping region
int flags // creation options
);
[DllImport("User32.DLL", EntryPoint="GetWindowDC", SetLastError=true,
CharSet=CharSet.Ansi, ExactSpelling=true,
CallingConvention=CallingConvention.Winapi)]
public static extern IntPtr GetWindowDC(
IntPtr hWnd // handle to window
);
private bool MouseMoveHandling(Point mousePosition)
{
Rectangle rect = ((NCButton)this.ncButtons[0]).ButtonRectangle;
if(rect.Contains(mousePosition))
{
RepaintTheNCArea();
graphics.DrawImage( ((NCButton)ncButtons[0]).FocusedButtonImage,((NCButton)ncButtons[0]).ButtonRectangle);
return true;
}
rect = ((NCButton)this.ncButtons[1]).ButtonRectangle;
if(rect.Contains(mousePosition))
{
RepaintTheNCArea();
graphics.DrawImage( ((NCButton)ncButtons[1]).FocusedButtonImage,((NCButton)ncButtons[1]).ButtonRectangle);
return true;
}
rect = ((NCButton)this.ncButtons[2]).ButtonRectangle;
if(rect.Contains(mousePosition))
{
RepaintTheNCArea();
graphics.DrawImage( ((NCButton)ncButtons[2]).FocusedButtonImage,((NCButton)ncButtons[2]).ButtonRectangle);
return true;
}
RepaintTheNCArea();
return false;
}
private bool MouseDownHandling(Point mousePosition)
{
Rectangle rect = ((NCButton)this.ncButtons[0]).ButtonRectangle;
if(rect.Contains(mousePosition))
{
RepaintTheNCArea();
graphics.DrawImage( ((NCButton)ncButtons[0]).PressedButtonImage,((NCButton)ncButtons[0]).ButtonRectangle);
return true;
}
rect = ((NCButton)this.ncButtons[1]).ButtonRectangle;
if(rect.Contains(mousePosition))
{
RepaintTheNCArea();
graphics.DrawImage( ((NCButton)ncButtons[1]).PressedButtonImage,((NCButton)ncButtons[1]).ButtonRectangle);
return true;
}
rect = ((NCButton)this.ncButtons[2]).ButtonRectangle;
if(rect.Contains(mousePosition))
{
RepaintTheNCArea();
graphics.DrawImage( ((NCButton)ncButtons[2]).PressedButtonImage,((NCButton)ncButtons[2]).ButtonRectangle);
return true;
}
RepaintTheNCArea();
return false;
}
private bool MouseUpHandling(Point mousePosition)
{
Rectangle rect = ((NCButton)this.ncButtons[0]).ButtonRectangle;
if(rect.Contains(mousePosition))
{
RepaintTheNCArea();
graphics.DrawImage( ((NCButton)ncButtons[0]).NormalButtonImage,((NCButton)ncButtons[0]).ButtonRectangle);
return true;
}
rect = ((NCButton)this.ncButtons[1]).ButtonRectangle;
if(rect.Contains(mousePosition))
{
RepaintTheNCArea();
graphics.DrawImage( ((NCButton)ncButtons[1]).NormalButtonImage,((NCButton)ncButtons[1]).ButtonRectangle);
return true;
}
rect = ((NCButton)this.ncButtons[2]).ButtonRectangle;
if(rect.Contains(mousePosition))
{
RepaintTheNCArea();
graphics.DrawImage( ((NCButton)ncButtons[2]).NormalButtonImage,((NCButton)ncButtons[2]).ButtonRectangle);
return true;
}
RepaintTheNCArea();
return false;
}
private Point FindMousePosition()
{
/*int l = (int)m.LParam;
int x = l & 0xffff;
int y = (int)((l & 0xffff0000) >> 16);
label1.Text = x.ToString();
label2.Text = y.ToString();*/
Point pt = System.Windows.Forms.Cursor.Position;
Point ptScreen = Cursor.Position;
Point ptClient = PointToClient(ptScreen);
ptClient.Y += 30;
//label1.Text = ptClient.X.ToString();
//label2.Text = ptClient.Y.ToString();
return ptClient;
}
private void RepaintTheNCArea()
{
if(graphics != null)
{
graphics.DrawImage(imgTitle,0,0,this.Width,30);
graphics.DrawImage( ((NCButton)ncButtons[0]).NormalButtonImage,((NCButton)ncButtons[0]).ButtonRectangle);
graphics.DrawImage( ((NCButton)ncButtons[1]).NormalButtonImage,((NCButton)ncButtons[1]).ButtonRectangle);
graphics.DrawImage( ((NCButton)ncButtons[2]).NormalButtonImage,((NCButton)ncButtons[2]).ButtonRectangle);
}
}
private void Form1_Resize(object sender, System.EventArgs e)
{
int totalButtonsWidth = 0;
int x = 0, y = 0 , w = 0, h = 0;
int space = 5;//space b/w the buttons;
for(int i = 0 ; i < ncButtons.Count ; i++)
{
totalButtonsWidth += ((NCButton)ncButtons[i]).NormalButtonImage.Width;
}
x = this.Width - ( (space * 2) + totalButtonsWidth) ;
y = 0;
w = ((NCButton)ncButtons[0]).NormalButtonImage.Width;
h = ((NCButton)ncButtons[0]).NormalButtonImage.Height;
Rectangle rect = new Rectangle(x,y,w,h);
((NCButton)ncButtons[0]).ButtonRectangle = rect;
x += (space + w) ;
y = 0;
w = ((NCButton)ncButtons[1]).NormalButtonImage.Width;
h = ((NCButton)ncButtons[1]).NormalButtonImage.Height;
rect = new Rectangle(x,y,w,h);
((NCButton)ncButtons[1]).ButtonRectangle = rect;
x += (space + w) ;
y = 0;
w = ((NCButton)ncButtons[2]).NormalButtonImage.Width;
h = ((NCButton)ncButtons[2]).NormalButtonImage.Height;
rect = new Rectangle(x,y,w,h);
((NCButton)ncButtons[2]).ButtonRectangle = rect;
}
}
}
|
|
|
|
|
hi,
Is it possible to explain your little more specific. What i mean is, what is your real requirement and where you fond problem. And what is your problem. When your form flickering. And what you mean by activate and deactivate. Is it forms activate and deactivate or something else
Sreejith Nair
|
|
|
|
|
hi
actually i am trying to create my own title bar(paint over the windows title) for this purpose i have images for my own buttons and for the title. on EM_NCPAINT i just paint these images over the title, i am also using the mouse events for the title buttons they also update my title bar.
But the problem is when i update my title bar as u seen in the previous message my window's titlebar flickers.
and the other problem is when i avtivate/deactivate my form (another app become over my form or vice versa it doesn't paint over the title bar.
by
|
|
|
|
|
hi,
So when ever you click on form say , for activating or deactivating you need to re- draw the client area. I mean the base form. Right. You can call Invalidate() of your base class to re-draw the region. And also you can try use DoubleBuffering to avoid flickering. I know this is not at all ultimate for you. But this is what i can suggest you now. Why i suggest you the double-buffering is, that you are trying to customize your title bar.
Sreejith Nair
|
|
|
|
|
hi
do u have any clue how to achieve DoubleBuffering in C# if yes please help me
thanx
|
|
|
|
|
hi,
In this point of time, I can't sound much in GDI+ .What i can do is , i can suggest one url page for you. There you will get more nice articles which will guide you to , how to use Double Buffering.
http://www.codeproject.com/script/Articles/list_articles.asp?userid=6556
please go to the Multimedia -> GDI + link. There you will get nice stuffs for DoubleBuffering with very nice exapmle.
Sreejith Nair
|
|
|
|
|
Hi Asif,
Add Paint Event handler and below line of code. This will solve your problem.
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
this.graphics = e.Graphics;
}
Do Revert back whether it could solve your problem or not.
Regards,
Jay.
|
|
|
|
|
this.graphics contains the handle of Non Client area if i equal it to my client area how will i paint over NC
thanx
|
|
|
|
|
Hi Asif,
Check out this code....
[DllImport("User32.Dll")]
public static extern IntPtr GetSystemMenu(int hWnd, bool bRevert);
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
IntPtr hTitle = GetSystemMenu(this.Handle, false);
this.graphics = Graphics.FromHwnd(hTitle);
}
Regards,
Jay.
|
|
|
|
|
GetSystemMenu only gets the graphics handle for the system menu .
i have the graphics handle for non client area but the problem is when i draw an image over another image it flickers is there any concept of double buffering
by
|
|
|
|
|
|
|