|
Yes I read the article, a very helpfull article in general but very short about this particular problem. As I stated above the invokation without filter works fine
Cheers
Stefan
|
|
|
|
|
Your IDataObject parameters - are you sure they are the COM interfaces and not the .NET interfaces (System.Windows.Forms.IDataObject )? These two interfaces are VERY different and won't be marshaled correctly. You must make sure that you use the IDataObject from COM, which should also have been defined when generating your RCW for the typelib containing IDocHostUIHandler (mshtmhst.dll) (and additional typelibs if forward-declaring additional interfaces from other typelibs).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Yes, I am using MsHtmHstInterop.IDataObject - and yes you are right using System.Windows.Forms.IDataObject is lethal...
Thanks
Stefan
|
|
|
|
|
Okay, then the "no-offense-meant,-I-have-to-ask" question: have you debugged your app and stepped through your implementation of FilterDataObject ? What appears to be happening in there?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Sure, you have to ask. When I step through the implementation the [in] IDataObject is valid and also the [out] IDataObject is either null or valid if I try to replace, but the return value S_OK, S_FALSE (which I have to set according to the MSDN) has no effect at all (either way & all combinations).
|
|
|
|
|
Is the method return Type an int or similar? If you generated this automatically, it should be void . In the case that you can't (or don't want to) redefine this yourself, you can throw a COMException with the result code. It seems weird, I know, but it works. So, to send S_FALSE (S_OK doesn't require this since not throwing an exception is the same as returning S_OK unless the function signature is defined correctly), throw new COMException(null, 1) . Hopefully this works for you.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thats actually the way I'm doing it: the signature is like this
void IDocHostUIHandler.FilterDataObject(MsHtmHstInterop.IDataObject pDO, out MsHtmHstInterop.IDataObject ppDORet)
I definded this 2 constants
const int S_OK = 0;
const int S_FALSE = 1;
up to now I return either
throw new COMException("", S_OK);
or
throw new COMException("", S_FALSE);
skipped
throw new COMException("", S_OK);
and
replaced
throw new COMException(null, S_FALSE);
no result so far...
Thanks for your kind replies, I will leave it for now (it's getting late here) - I will figure it out sooner or later.
Cheers
Stefan
|
|
|
|
|
Hi guys!
My question is certainly trivial for you...
I want to convert the text of a textbox to a float with two digits after the separator. And then the whole thing backwards: Convert the float to a string, always showing two digits after the separator.
Right now I do it like that:
float myFloat = float.Parse(TextBox1.Text);
TextBox1.Text = myFloat.ToString(); Everything works fine except for trailing zeros (e.g. '12,30' or 123,00'). The textbox doesn't show any trailing zeros. (I use a comma as separator cause it's a german application)
What can I do to show trailing zeros? Do I have to use IFormatProvider in some way?
Btw... these variables represent amounts of money (€). Is it possible to set somthing like a "currency-mode" for the textbox?
Many thanks in advance!
mYkel
|
|
|
|
|
TextBox1.Text = myFloat.ToString("F");
Charlie
if(!curlies){ return; }
|
|
|
|
|
TextBox1.Text = myFloat.ToString("c");
check out Chris Sells format designer to experiment with format strings :
http://www.sellsbrothers.com/tools/#FormatDesigner
The smaller the mind the greater the conceit.
Aesop
|
|
|
|
|
"C" and "c" are the format specifiers for currency, so unless you want a currency symbol in your number, don't use it. Instead, use "F" or "f" instead.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Good point, he did say 'Is it possible to set somthing like a "currency-mode" for the textbox?' though so I though thats what he wanted.
Cheers.
The smaller the mind the greater the conceit.
Aesop
|
|
|
|
|
You're absolutely right, sorry! A lot of sentences in there and I guess I missed the last one.
In any case - to the original poster if you're following along - you should look at the CultureInfo class and its related properties (IFormatProvider implementations). For most ToString overloads (not the override from Object or another base class), the IFormatProvider (like the NumberFormatInfo ) is used for the Thread.CurrentUICulture , so you don't really need to specify one unless you want to format for a different culture (just for that instance, otherwise you should set Thread.CurrentUICulture and re-initialize your controls) or pass your own IFormatProvider . Typically, such a ToString method (or methods like String.Format ) will specify if they use the current CultureInfo for the format specifier.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks so much for your numerous and quick answers! I knew there is a simple solution...
The myFloat.ToString("F") does all I need.
There's no difference between "f" and "F", right?
Regards, mYkel
|
|
|
|
|
Mykel wrote:
There's no difference between "f" and "F", right?
Nope. See the documentation for NumberFormatInfo in the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi C# masters,
While I continue my investigation on C#, I'm currently testing some techniques I was used to use in MFC.
I have done the following things:
I derived a UserControl to write my own control. In the OnPaint overridable method, I want to do my drawings. As C# uses GDI+, it's cool, I also use GDI+ in C++.
In MFC I was doing the following thing:
- Instanciate a Bitmap object with the width, height, and color depth
- Link a Graphics object to this bitmap
- Work with this graphic object to generate my bitmap
- When the bitmap was generated, I displayed it on the drawing context.
Therefore, it looks like this
in MFC:
<br />
<br />
...<br />
class CMyWnd : public CWnd<br />
{<br />
...<br />
afx_msg void OnPaint();<br />
...<br />
}<br />
<br />
...<br />
<br />
void CMyWnd::OnPaint()<br />
{<br />
CPaintDC dc(this);<br />
Rect rect;<br />
<br />
GetClientRect((LPRECT) &rect);<br />
<br />
Bitmap bmp(rect.Width, rect.Height, PixelFormat32Bpp);<br />
Graphics memGraphics(&bmp);<br />
Color clr;<br />
<br />
clr.SetFromCOLORREF(::GetSysColor(COLOR_3DFACE));<br />
<br />
SolidBrush brush(clr);<br />
Pen pen(Color::Red);<br />
<br />
memGraphics.FillRectangle(brush, rect);
memGraphics.DrawLine(&pen, rect.X, rect.Y, rect.Width, rect.Height)
<br />
Graphics graphics(&dc);<br />
graphics.DrawImage(&bmp, rect);<br />
}<br />
And there were no flickering while resizing on the fly the derived window
So, I applied this technique to C#
<br />
protected override void OnPaint(PaintEventArgs e)<br />
{<br />
Bitmap bmp=new Bitmap(ClientRectangle.Width, ClientRectangle.Height);<br />
Graphics memGraphics=Graphics.FromImage(bmp);<br />
Pen pen=new Pen(Color.Red);<br />
Brush brush=new SolidBrush(SystemColors.Control);<br />
<br />
memGraphics.FillRectangle(brush, ClientRectangle);<br />
memGraphics.DrawLine(pen, ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, ClientRectangle.Height);<br />
<br />
e.graphics.DrawImage(bmp, ClientRectangle);<br />
}<br />
I remind that the Bitmap object is instancied on both languages to work on a bitmap in memory and once finished, I display the result.
But, in C#, when I resize the control on the fly, there is still flickering
Can any C# master explain me why???
Thanks.
|
|
|
|
|
First of all, when overriding an event handler like OnPaint , always call the method on the base class (ex, base.OnPaint ) unless you have a VERY good reason not too. The base class might have things it needs to do as well, and if you don't the Paint event won't be fired for other, outside classes to handle. Also, whenever you're done with a Bitmap , call Dispose on it or memory consumption increases rapidly. This could be one reason for the flickering. The GC will clean it up eventually, but not in a timely enough manner - especially when the app is busy doing a lot of repainting that occurs when you resize.
Also, for things that don't change - like your Pen , you can store these as fields if time is a big issue, but you should normally dispose those as well.
Finally, you can call SetStyle with ControlStyles.AllPaintingInWmPaint , ControlStyles.DoubleBuffer , and ControlStyles.UserPaint in order to tell the Framework (or rather the underlying system resources) to use double-buffering when painting. This works in most cases.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi there,
How can I link a Bitmap object to a Graphics object in C#?
In C++ we can do this:
Bitmap bmp(100, 100, PixelFormat32Bpp);
Graphics memGraphics(&bmp);
How to do the same in C#?
This does not work in C#
Bitmap bmp(100, 100);
Graphics memGraphics(bmp);
Best regards.
Thanks.
|
|
|
|
|
Graphics.DrawImage()
Mazy
"Art is life, life is life, but to lead life artistically is the art of life." - Peter Altenberg
|
|
|
|
|
yes, but I have do draw lines etc from graphics, in my bitmap....
|
|
|
|
|
Graphics.FromImage(bitmapobject);
Mazy
"Art is life, life is life, but to lead life artistically is the art of life." - Peter Altenberg
|
|
|
|
|
Ok. it works
Thanks.
|
|
|
|
|
hey,
im coding a system in c#...i have got four buttons that link to four diff departments
in the system. these buttons when clicked, opens up the same dialog box which requires a username and
password to access to the respective parts of the system(according to the buttons).
the user name and password is different for each department is it possible for me to use "if else" statements to check
the passwords from the database(SQL).
i've coded in plain english just to check if its logic and possible
private void btnOK_Click(object sender, System.EventArgs e) //ok button on the password dialog box
{
if (btnReg was clicked)
{
check for user name and password in the REG table
if (username and password is correct)
{
allow access
}
else
{
messagebox saying incorrect password
}
}
if (btnDiag was clicked)
{
check for user name and password in the DIAG table
if (username and password is correct)
{
allow access
}
else
{
messagebox saying incorrect password
}
}
}
and so on for the rest of the buttons....
if this is not possible...then is there anyway i can do this...or do i have to code four different password dialog boxes for
each of the buttons which will not be very good for the system, design wise and also extra coding....arrrgghh!! HELP!!
ArvinderGill
Arvinder Singh Gill
|
|
|
|
|
I take it all of the buttons are wired up to the same event?
If so the 'sender' variable is the textbox 'sending' the 'on_click' event. You can then cast the sender variable to a control of type 'textbox'
[code]
TetxtBox txt = (TextBox)s;
[/code]
and evaluate the id etc with either a switch/case statement as below...
[code]
switch(txt.ID)
{
case "ID1":
//Function to check password 1
break;
case "ID2":
//Function to check password 2
break;
case "ID3":
//Function to check password 3
break;
case "ID4":
//Function to check password 4
break;
default:
//Default password failure?
break;
}
[/code]
...or with an If Else statement, that would be up to you. Of course you're password checking could be all nicely wrapped up in it's own class etc.
Hope this is in any way helpful...
Rhys Gravell
|
|
|
|
|
Before showing the dialog, set a property you'd add to the Form that dictates which button was clicked, like an enumeration for example (provides easy value checking to make sure an invalid enumeration wasn't passed in - see Enum.IsDefined ).
You could also use a generic prompt Form that has a username and password property that gets the text from their respective TextBox controls in the Form and, if ShowDialog returned DialogResult.OK handle the code in each one of the Click event handlers for the departmental Button s. If you put this in a terminating loop (for which you can always use break to break out of it if the credentials were authenticated successfully), the dialog could be shown multiple times - even using the same instance. Just don't forget to call Dispose when you're finally done with the Form to free system resources, which is necessary for modal dialogs (i.e., when calling Form.ShowDialog , which has to do with the underlying native resources used by the Form ).
There's many other ways you can do this. Personally, I would've invoked the call on some sort of broker since your code to check the database is most likely the same except for, perhaps, the connection string and the query string. If you passed an instance of an object configured with the write departmental connection and query strings, the prompt could simply call a single method and know whether or not the credentials are valid without even knowing which department is authenticating the credentials. After all, it's just a generic prompt dialog - why should it care about how to authenticate credentials. Just use the power of polymorphism. For instance, if you have an interface like so:
public interface IAuthenticator
{
bool Authenticate(string username, string password);
} ...and had a property that takes an instance of this interface (by declaring a property of Type IAuthenticator ), then when the user tries clicks OK (or Login, or whatever) you make sure this property isn't null and call Authenticate on the instance. Any code that wants to authenticate credentials merely implements this interface and provides a specific implementation of Authenticate . This is a good abstract design.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|