|
Well, maybe still not very clear in my previous reply.
I included a picture of the button control I've been
writing for fun.
http://www.ykliu.com/problem.png[^]
It's a small button that draw everything from scratch. I plan a
few features for this button:
- support theme automatically. done! (Thanks for help from James T. Johnson)
- support shadowed text. done! (Thanks for great tutorials from Christian Graus)
- to able to draw underlying control, so it looks like transparent background is supported.
Well, that's why I come up with this question.
Though, I am able to use InvokePaint, InvokePaintBackground to redraw the
underlying parent control. Suddenly this question comes to my mind. If
I want to write another custom control that use this feature by using
InvokePaint. There is no way but inheriting it from Control Class.
Wouldn't it be better if I can write a static function, passing the caller
control and caller's parent control as parameter, then the function will
repaint caller control with the underlying parent's background.
Thanks in advance...
P.S. there's also another painting problem I found. illustrated in the included image.
Li-kai Liu
|
|
|
|
|
Can anyone show an example of using the Win32 SendInput function in C#? It seems to be missing from dotnet and I need to send a keyboard event,
thanks
"Outside of a dog, a book is Man’s best friend. And inside of a dog, it’s too dark to read."
-Groucho Marx
|
|
|
|
|
Google!
link[^]
How low can you go ? (MS retrofuck)
|
|
|
|
|
I saw that google link, and I've been working on it, but I still can't get it to work. I've reached the point where it neither throws errors, nor works.
My definitions are like this:
<br />
[System.Runtime.InteropServices.DllImportAttribute("user32.dll")]<br />
private static extern uint SendInput(<br />
uint nInputs,
INPUT[] pInputs,
int cbSize
);<br />
<br />
public struct INPUT {<br />
public int type;<br />
public short wVk;<br />
public short wScan;<br />
public int dwFlags;<br />
public int time;<br />
public UIntPtr dwExtraInfo;<br />
private int _pad0, _pad1;<br />
}<br />
<br />
I call it like this:<br />
<br />
INPUT[] ipar=new INPUT[1];<br />
INPUT m=new INPUT();<br />
ipar[0]=m;<br />
m.type= 1;
m.wVk= 0x41;
m.wScan= 0; <br />
m.dwFlags=0;<br />
m.time=0;<br />
uint u=0;<br />
m.dwExtraInfo=(System.UIntPtr)u;<br />
tbx.Focus();
uint ui=SendInput(1,ipar,System.Runtime.InteropServices.Marshal.SizeOf(m));<br />
<br />
the result is that ui = 1. But the Textbox stays empty.
I also tried it by doing the union inside the INPUT and making structs for hardware and mouse input, and I got that to the same point, where ui=1 but the textbox stays empty. This always what happens to me with com interop I get to the point where there's no errors but doesn't work.
"Outside of a dog, a book is Man’s best friend. And inside of a dog, it’s too dark to read."
-Groucho Marx
|
|
|
|
|
Hi
I think your txtbox is not getting the focus. I have had problems before. You mite need to invoke the Focus method.
Hope this helps
"There are no stupid question's, just stupid people."
|
|
|
|
|
er I did invoke the Focus method, take another look at the code. Also, I know it's focused because i can see the cursor blinking in it, and the border etc..
"Outside of a dog, a book is Man’s best friend. And inside of a dog, it’s too dark to read."
-Groucho Marx
|
|
|
|
|
Bog wrote:
er I did invoke the Focus method, take another look at the code.
tbx.Focus(); only calls the function.
You will need to do something like this I suspect.
if (tbx.InvokeRequired) tbx.Invoke(tbx.Focus);
else tbx.Focus();
Also I see that there is no KEYEVENTF_KEYUP for the SendInput. This I presume you will need to do after the first SendInput you are sending.
"There are no stupid question's, just stupid people."
|
|
|
|
|
I tried a Console.WriteLine(tbx.InvokeRequired) and it was false. Also, I know the textbox is getting focus because I can see it. The curosor is blinking in the textbox, and when I type text goes into it.
I don't think sending a KEYUP is required, because it's not required in normal keyboard activity either. For example, when you press a key here in a web form, the letter appears on keydown, not on keyup. Also, I've seen examples of this in C++ (non dotnet) and non of the examples have a subsequent KEYUP.
Thanks for your responses anyway tho.
"Outside of a dog, a book is Man’s best friend. And inside of a dog, it’s too dark to read."
-Groucho Marx
|
|
|
|
|
Hello,
i am very new to c#.
i made a program to download a web page.
Now I want to parse out the meta keyword tags:
Done any hacking lately?
|
|
|
|
|
Add the Microsoft.mshtml namespace (add a reference to this primary assembly that you'll find in the program files \ .NET folder).
Then the IHTMLMetaElement interface is the right stuff for you.
How low can you go ? (MS retrofuck)
|
|
|
|
|
Thanks - that pointed me in the right direction.
I have managed to get the keywords out, but I think that regular expressions could do it much quicker for me. I am looking into those right now If you have any experience with regular expressions, please look at my new post
Cheers,
Jeremy
Jeremy Pullicino
Professional C++ Developer
Amature C# Software Architect
Done any hacking lately?
|
|
|
|
|
My C# app calls a COM server but does not release it. What's Wrong? Urgent!
Please help!
Here is how I call it:
<code>
...
void SomeFunc1()
{
for (int i; i<10; i++)
{
SomeFunc2();
}
}
void SomeFunc2()
{
MyCOMLib.MyIFace mf = null;
try
{
mf = new MyCOMLib.MyIFace();
string myParam = "Here is some param";
MyCOMLib.MyIFace2 mf2 = mf.MyMethod(myParam);
mf2.MyProperty = 1;
}
catch()
...
}
</code>
|
|
|
|
|
Not really surprising.
Anyway, help the GC by doing stuff like mf2.Release() and mf = null;
(may be the issue is on your part btw : if you have a wrong apartment model, then the COM server is not released that easy).
How low can you go ? (MS retrofuck)
|
|
|
|
|
The problem is that for some reason, even when COM interface
IUnknown derived C# compiler throuws at me:
MyCOMLib.MyIFace2 does not contain a definition for 'Release'
and assigning to null does not release it right away for sure.
How do I work this appartment thing?
|
|
|
|
|
O! So GC does not release objects right away, does it?!
It looks like if I call GC.Collect(); objects do get released (not right there but in a couple of milsecs).
I'm assuming that means that my COM objects are fine and can be released just fine, right? Or is this GC.Collect(); a kind of cheating?
If not, why GC doesn't clear local vars right there on the spot like VB does (I think ) ? When does it do it?
|
|
|
|
|
GC.Collect() is kinda hardcore. This method is not normally called by a client app, except in critical scenarios (huge memory needs, and so on). It's true that, from what I know from the Java GC, the GC has no good reason to release objects as soon as they are out of scope.
The fact that GC.Collect() has actually released your COM object is that it was a weak-reference in scope.
COM are normaly finely released.
How low can you go ? (MS retrofuck)
|
|
|
|
|
Interesting! Thanks a lot.
Curious : what's "weak-reference"?
And what do you mean by "COM are normaly finely released"?
May be my english is not that good yet
Do you think I still have to hunt for problem or it looks like it's fine. What do I do?
|
|
|
|
|
Here is an article [^]explaining how the GC works, and what is a weak reference.
You'll notice it's about Sun's GC. But when you know where the .NET virtual machine comes from...
How low can you go ? (MS retrofuck)
|
|
|
|
|
Hi,
I'm trying to call functions exposed by a .Net application (exe, not dll) from a COM client. The problem is that the tlb generated by regasm (or tlbexp) doesn't have enough info. I assume I need to use some funky attributes, but I just can't find them.
Does anyone have an idea?
Thanks,
Bruno
|
|
|
|
|
ComVisible and ComSource
How low can you go ? (MS retrofuck)
|
|
|
|
|
ComVisible determines if a class/method is visible to COM, but has no effect in exes. ComSource is linked to events; I don't need those. Am I missing something?
Also, can you please explain the last part? The one with "how low..".
|
|
|
|
|
Those are entry points. If you check out .NET samples, or google, you'll find implementations that might help you.
How low can you go ? (MS retrofuck)
|
|
|
|
|
I'm totally new to programming so don't expect me to know anything =)
I've been trying to write a simple program too list all the installed fonts in a simple list,
This I've accomplished with this code:
FontFamily[] fontFamilies;
InstalledFontCollection installedFontCollection = new InstalledFontCollection();
// Get the array of FontFamily objects.
fontFamilies = installedFontCollection.Families;
int count = fontFamilies.Length;
for(int j = 0; j < count; ++j)
{
listView1.Items.Add(fontFamilies[j].Name);
}
It adds lines to the listView1.
How would I now continue with my project and try to get the fonts to display in their own typeface, since they now are printed using the default system font.
Cheers
|
|
|
|
|
Essentially iterating through your array, make sure you have a graphics object when doing this (e.g. - grfx ):
<code>
Color c = Color.Black;
Brush brush = new SolidBrush(c);
float y = 0;
FontFamily[] aff = FontFamily.Families;
foreach (FontFamily ff in aff)
{
Font font = new Font(ff, 12);
grfx.DrawString(ff.Name, font, brush, 0, y);
y += font.GetHeight(grfx);
}
</code>
HTH
Nick Parker
The greatest lesson in life is to know that even fools are right sometimes. - Winston Churchill
|
|
|
|
|
using System;
using System.Drawing;
using System.Drawing.Text;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace FontViewer
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// 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.
///
private void InitializeComponent()
{
System.Configuration.AppSettingsReader configurationAppSettings = new System.Configuration.AppSettingsReader();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.listView1 = new System.Windows.Forms.ListView();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.SuspendLayout();
//
// tabControl1
//
this.tabControl1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.tabPage1});
this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(624, 353);
this.tabControl1.TabIndex = 2;
//
// tabPage1
//
this.tabPage1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.listView1});
this.tabPage1.Location = new System.Drawing.Point(4, 22);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Size = new System.Drawing.Size(616, 327);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "Installed Fonts";
//
// listView1
//
this.listView1.CausesValidation = false;
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader2});
this.listView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.listView1.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.listView1.MultiSelect = false;
this.listView1.Name = "listView1";
this.listView1.Scrollable = ((bool)(configurationAppSettings.GetValue("listView1.Scrollable", typeof(bool))));
this.listView1.Size = new System.Drawing.Size(616, 327);
this.listView1.Sorting = System.Windows.Forms.SortOrder.Ascending;
this.listView1.TabIndex = 1;
this.listView1.View = System.Windows.Forms.View.Details;
//
// columnHeader2
//
this.columnHeader2.Text = "Names";
this.columnHeader2.Width = 595;
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItem3});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2});
this.menuItem1.Text = "File";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Shortcut = System.Windows.Forms.Shortcut.CtrlQ;
this.menuItem2.Text = "Exit";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// menuItem3
//
this.menuItem3.Index = 1;
this.menuItem3.Text = "About";
this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
//
// columnHeader1
//
this.columnHeader1.Width = 612;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(624, 353);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.tabControl1});
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "Leons Font Program";
this.Load += new System.EventHandler(this.Form1_Load);
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
Graphics grfx = CreateGraphics();
Color c = Color.Black;
Brush brush = new SolidBrush(c);
float y = 0;
FontFamily[] aff = FontFamily.Families;
foreach (FontFamily ff in aff)
{
if(ff.IsStyleAvailable(FontStyle.Regular))
{
Font font = new Font(ff, 12);
grfx.DrawString(ff.Name, font, brush, 0, y);
y += font.GetHeight(grfx);
}
}
}
private void menuItem3_Click(object sender, System.EventArgs e)
{
MessageBox.Show("Made By Leon Radley, 2002");
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
}
}
Here's my program, the problem is that nothing shows when I compile it... what have I done wrong?
|
|
|
|