|
hi,
before some time ago , i face this problem. i find the net to resolve this problem and find solution which i decribe below. Note that following code is in vb.net so convert it in c#
first of all add this font to your application for example "ITCKRIST.TTF"
now imports following namespace in module or form level
Imports System.Drawing<br />
Imports System.Text<br />
Imports System.Collections.Generic<br />
Imports System.ComponentModel<br />
now call the following API as following
Private Declare Auto Function AddFontMemResourceEx Lib "Gdi32.dll" _<br />
(ByVal pbFont As IntPtr, ByVal cbFont As Integer, _<br />
ByVal pdv As Integer, ByRef pcFonts As Integer) As IntPtr<br />
now write a function as following
Public Function GetFont(ByVal FontResource() As String) As _<br />
Drawing.Text.PrivateFontCollection<br />
'Get the namespace of the application <br />
Dim NameSpc As String = _<br />
Reflection.Assembly.GetExecutingAssembly().GetName().Name.ToString()<br />
Dim FntStrm As IO.Stream<br />
Dim FntFC As New Drawing.Text.PrivateFontCollection()<br />
Dim i As Integer<br />
For i = 0 To FontResource.GetUpperBound(0)<br />
'Get the resource stream area where the font is located<br />
FntStrm = _<br />
Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream( _<br />
NameSpc + "." + FontResource(i))<br />
'Load the font off the stream into a byte array<br />
Dim ByteStrm(CType(FntStrm.Length, Integer)) As Byte<br />
FntStrm.Read(ByteStrm, 0, Int(CType(FntStrm.Length, Integer)))<br />
'Allocate some memory on the global heap<br />
Dim FntPtr As IntPtr = _<br />
Runtime.InteropServices.Marshal.AllocHGlobal( _<br />
Runtime.InteropServices.Marshal.SizeOf(GetType(Byte)) * _<br />
ByteStrm.Length)<br />
'Copy the byte array holding the font into the allocated memory.<br />
Runtime.InteropServices.Marshal.Copy(ByteStrm, 0, _<br />
FntPtr, ByteStrm.Length)<br />
'Add the font to the PrivateFontCollection<br />
FntFC.AddMemoryFont(FntPtr, ByteStrm.Length)<br />
Dim pcFonts As Int32<br />
pcFonts = 1<br />
AddFontMemResourceEx(FntPtr, ByteStrm.Length, 0, pcFonts)<br />
'Free the memory<br />
Runtime.InteropServices.Marshal.FreeHGlobal(FntPtr)<br />
Next<br />
Return FntFC<br />
End Function<br />
<br />
almost work is done . Now you can change font of any control. for example
dim strFont(0) As String<br />
dim FntFC As New Drawing.Text.PrivateFontCollection()<br />
<br />
strFont(0) = "ITCKRIST.TTF"<br />
FntFC = GetFont(strFont)<br />
<br />
Label1.Font = New Font(FntFC.Families(0), 16)<br />
Label2.Font = New Font(FntFC.Families(0), 16)<br />
hope this helps
Rupesh Kumar Swami
Software Engineer,
Integrated Solution,
Bikaner (India)
My Company
|
|
|
|
|
In the setup program click add special folder and choose Fonts Folder. Add your font to that folder. The font will be automatically installed and uninstalled together with your program
|
|
|
|
|
hi Giorgi,
your solution is better from my solution.
difference is that my solution is work for specific application ,not for all.
thanks
Rupesh Kumar Swami
Software Engineer,
Integrated Solution,
Bikaner (India)
My Company
|
|
|
|
|
Hi
I have classes property and sketch in htis property will be linked to skecth class
and foure different classes which r linked to the skecth class
and two generic list one is for skecth and other is for data of type Object
when i run the program i iam grtting the error here
public Sketch FirstData()
{
// return Datas[Datas.Count];
foreach (Object data in Datas)
{
if (data is Door)
{
Door door = (Door)data;
}
if (data is Fixture)
{
Fixture fixture = (Fixture)data;
}
if (data is Wall)
{
Wall wall = (Wall)data;
}
if (data is Window)
{
Window window = (Window)data;
}
//return
}
return getSketch(1);
}
private Sketch getSketch(Int32 id)
{
foreach (Object data in Datas)
{
if (data is Door)
{
Door door = (Door)data;
door.Id = id;
}
if (data is Fixture)
{
Fixture fixture = (Fixture)data;
fixture.Id = id;
}
if (data is Wall)
{
Wall wall = (Wall)data;
wall.Id = id;
}
if (data is Window)
{
Window window = (Window)data;
window.Id = id;
}
}
return getSketch(id);
}
An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll
how can i slove this problem?
can any one help me in this
|
|
|
|
|
Hello,
The problem is that you call "getSketch(id)" recursive!
"return getSketch(id);"
You will never come out of this method.
I'm not sure what this program should do, but I have the feeling that the "getSketch" method should somewhere instanciate a "Sketch" object and return this one.
Apart from that you should really work with interfaces, as you have to check four types and write at the same param.
Hope it helps!
All the best,
Martin
|
|
|
|
|
I have created an Int128 class, but am having trouble with my ToString method (converting to base 10). I cannot figure out why I am getting incorrect results. The applicable code is as follows (within a class named "TestUInt"):
private ulong m_LBits, m_HBits;
public TestUInt(ulong high, ulong low) {
m_HBits = high;
m_LBits = low;
}
private static void Divide(TestUInt dividend, TestUInt divisor, out TestUInt quotient, out TestUInt remainder) {
if (divisor == 0ul)
throw new DivideByZeroException();
quotient = 0;
remainder = 0;
if (divisor < dividend) {
remainder = dividend;
} else if (dividend == divisor) {
quotient = 1;
} else if (dividend != 0ul) {
int divBits = Log2(dividend);
int performedOps = 0;
int requiredOps = divBits - Log2(divisor);
for (TestUInt comparator = divisor << requiredOps; divBits >= 64
&& performedOps <= requiredOps; comparator >>= 1, ++performedOps, --divBits) {
quotient <<= 1;
if (dividend >= comparator) {
dividend -= comparator;
quotient.m_LBits |= 1;
}
}
if (performedOps <= requiredOps) {
quotient <<= requiredOps - performedOps + 1;
quotient.m_LBits |= dividend.m_LBits / divisor.m_LBits;
dividend = dividend.m_LBits % divisor.m_LBits;
}
remainder = dividend;
}
}
private static int Log2(TestUInt value) {
if (value.m_HBits != 0)
return MathExtension.Log2(value.m_HBits) + 64;
else
return MathExtension.Log2(value.m_LBits);
}
public static TestUInt operator -(TestUInt a, TestUInt b) {
ulong old_lbits = a.m_LBits;
a.m_LBits -= b.m_LBits;
a.m_HBits -= b.m_HBits;
if (a.m_LBits > old_lbits)
--a.m_HBits;
return a;
}
public static TestUInt operator <<(TestUInt a, int b) {
b &= 127;
if (b == 0) {
return new TestUInt(a.m_HBits, a.m_LBits);
} else if (b >= 64) {
return new TestUInt(a.m_LBits << b - 64, 0);
} else {
return new TestUInt(a.m_HBits << b | a.m_LBits >> 64 - b, a.m_LBits << b);
}
}
public static TestUInt operator >>(TestUInt a, int b) {
b &= 127;
if (b == 0) {
return new TestUInt(a.m_HBits, a.m_LBits);
} else if (b >= 64) {
return new TestUInt(0, a.m_HBits >> b - 64);
} else {
return new TestUInt(a.m_HBits >> b, a.m_HBits << 64 - b | a.m_LBits >> b);
}
}
public static bool operator ==(TestUInt a, TestUInt b) {
return (a.m_LBits == b.m_LBits && a.m_HBits == b.m_HBits);
}
public static bool operator !=(TestUInt a, TestUInt b) {
return (a.m_LBits != b.m_LBits || a.m_HBits != b.m_HBits);
}
public static bool operator <=(TestUInt a, TestUInt b) {
return (a.m_HBits == b.m_HBits ? a.m_LBits <= b.m_LBits : a.m_HBits <= b.m_HBits);
}
public static bool operator >=(TestUInt a, TestUInt b) {
return (a.m_HBits == b.m_HBits ? a.m_LBits >= b.m_LBits : a.m_HBits >= b.m_HBits);
}
public static bool operator <(TestUInt a, TestUInt b) {
return (a.m_HBits == b.m_HBits ? a.m_LBits < b.m_LBits : a.m_HBits < b.m_HBits);
}
public static bool operator >(TestUInt a, TestUInt b) {
return (a.m_HBits == b.m_HBits ? a.m_LBits > b.m_LBits : a.m_HBits > b.m_HBits);
}
public static implicit operator TestUInt(ulong value) {
return new TestUInt(0, value);
}
public override string ToString() {
TestUInt quotient = this, remainder;
string rval = string.Empty;
while (quotient.m_HBits != 0) {
Divide(quotient, 1000000000000000000ul, out quotient, out remainder);
rval = remainder.m_LBits.ToString("D18") + rval;
}
rval = quotient.m_LBits.ToString("D") + rval;
return rval;
} I know that the 'Divide' method is not working (or my theory on how to print integers in base 10 is wrong), because if I change the method "ToString" to use, say 1000 instead of 1000000000000000000, I get a different output. My test application works as follows:
string line = "{0,-3} {1,-3}\r\n {2}\r\n {3}";
UInt128 c = new UInt128(0x4C8A5BB86B074FBD, 0x7A223174473F3F4B);
UInt128 d = new UInt128(0x00000000467471AB, 0x1F2DA3680D768689);
UInt128 e = new UInt128(1, 2);
UInt128 f = 0x1000000000;
UInt128 g = new UInt128(0x11, 0xF000000000000000);
UInt128 h = new UInt128(0x01, 0x1C2A19B300000000);
Console.WriteLine(string.Format(line, "Var", "Frm", "Result", "Computed"));
Console.WriteLine(string.Format(line, "c", "", "101739724956510982573881893874860769099", c.ToString()));
Console.WriteLine(string.Format(line, "d", "", "21804722866621884125668607625", d.ToString()));
Console.WriteLine(string.Format(line, "e", "", "18446744073709551618", e.ToString()));
Console.WriteLine(string.Format(line, "h", "", "20476206912383221760", h.ToString())); Again, sorry for the long post, but hopefully someone is willing to give me some pointers here as to why my ToString method isn't working. Thanks,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Hi Jeff,
I did not study your code in any detail, but have some suggestions.
may I suggest you do all testing and debugging in hex until you are satisfied by
the results. Hex input/ouput will easily reveal where things go wrong when they do.
Also start with small divisors, and keep them a power of 2 or 16 for starters.
With simple hex numbers it should be rather easy to figure out when ToString
fails whether it is due to the Divide method or the ToString logic itself.
I once did a biginteger class (with thousands of uints in one number), but did
the ToString() completely different: rather than executing the expensive
full-divide, I did a much cheaper divide-by-10 for each digit, from right to left.
Also biginteger packages are ideal candidates for NUnit testing, first to check
internal functions such as Log2, then the public methods.
PS: I am unsure about operator precendence in lines such as
return new TestUInt(a.m_HBits << b | a.m_LBits >> 64 - b, a.m_LBits << b);
so I would suggest you add some parentheses to make sure it works correctly.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
I am just using the operator precedence I found here[^], which is basically the following (for my purpose)...
* / % (Multiplicative)
+ - (Additive)
>> << (Shift)
| & ^ (Bitwise) However, it would definitely add readability if I were to include parenthesis, so I will probably fill those in eventually. The thing that interests me most from your post is the more efficient printing algorithm. My current division algorithm takes time O(n^2), where 'n' is the difference between the number of bits in the divisor and the number of bits in the dividend. Therefore, I attempt to minimize both the number of divisions and the time it takes per division by dividing by the largest multiple of 10 <= 2^64. I don't really understand how I could divide by 10 and get faster results, so a brief explanation of how you implement such an algorithm would really be appreciated. Oh, and I did do some arithmetic with both division and moduli, and based on my incorrect results printing the numbers in decimal, I discovered that the following yields errors:
TestUInt foo = new TestUInt(1, 2);
TestUInt quotient = foo / 1000;
TestUInt modulus = foo % 1000; Thanks for the pointers,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Hi Jeff,
Two points to clarify what I said earlier:
1.
for big integers the theory on division algorithms can fill many books; there
are ways much more appropriate than the shift-and-try-to-subtract approach,
especially for *large* numbers. Of course for 128-bit or so, it probably does
not matter much.
2.
I did my ToString() long before I even attempted to do a general divide;
after all, dividing by 10 is a very simple special case, since the divisor
is both small and a known constant. So the easiest approach is by repeated MOD10/DIV10
operations. Your divide-by-a-large-power-of-10, then let .NET take care of
the details, is viable too, of course, provided your division is correct...
Cheers.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Found it. In my Divide method, my logic was as follows:
1. If divisor == 0, throw DivideByZeroException
2. If divisor > dividend, return (0 R dividend)
3. If divisor == dividend, return (1 R 0)
4. Shift the divisor left until Log2(divisor) == Log2(dividend)
5. While the dividend > ulong.MaxValue, do repeated subtraction
6. Use the built-in ulong division / modulo methods to obtain the result. My error was in step #5. In my divide method, I continued doing repeated subtraction until the number of bits in the shifted divisor was < 64. However, just because the base-2 log of the divisor was < 64 does not mean that the partial difference is as well. I simply changed the condition "divBits >= 64" to "divBits >= 63", and it now works just fine, as the partial difference is now guaranteed to be <= ulong.MaxValue. Thanks for the help,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
This seems simple but I have a background image on my MDIparent form. The imagelayout is set to center. Now when the form is resized I have the form refresh() so the image will appear back in the center of the form after it has been resized. This works fine, but when you use the control boxes at the top right (minimize, maximize, exit) it does not work. What function is called when those buttons are used? The way I have it when you click Maximize the center image will stay at where it was before it was maxed, but then it looks like it tries to put the same image in the center.. so I have half of a image under the full image before the form was maximized???
If the refresh() trying to repaint the image again? Is this why it is doing this? This does not happen when I resize the form instead of using the max button.
|
|
|
|
|
I figured it out... ClientSizeChanged
|
|
|
|
|
Hello,
I want to change the gradient background of my button. It's easy to change the background color, but using a custom gradient is obviously less straight forward.
Could someone point me in the right direction?
Thanks!
Ian
|
|
|
|
|
well, i´d say create a custom control, inherit from button
and try something like his in the overridden OnPaint Method
<br />
Graphics g = pe.Graphics;
Rectangle bg = new Rectangle(0, 0, this.Width, this.Height);<br />
System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(bg, PageStartColor, PageEndColor, 0.0);<br />
g.FillRectangle(brush, bg);<br />
brush.Dispose();
|
|
|
|
|
Thanks for taking the time! I appreciate it!
I'll try this solution.
|
|
|
|
|
here is code for you !!!!
<br />
Bitmap bmp = new Bitmap(500, 500);<br />
Graphics G = Graphics.FromImage(bmp);<br />
LinearGradientBrush Lb = new LinearGradientBrush(new Point(0, 0), new Point(100, 100), Color.Red, Color.Green);<br />
G.FillRectangle(Lb, new Rectangle(0, 0, 100, 100));<br />
button1.BackgroundImage = bmp;
|
|
|
|
|
Thanks for taking the time! I appreciate it!
I'll give it a shot.
|
|
|
|
|
|
Thanks for the link! I'll check it out.
|
|
|
|
|
I need some assistance resolving this issue. In the DragOver method I need to identify the column panel that a control was assigned to before assigning it back again to the main form for the application. The question is, what is the correct approach to assign the control back to the application main form so that the NewLocation() function can assign it to a new location on the main form? Currently, the control only stops dragging when I attempt to drag the control onto the control on that Panel object. I need the control that is dragged to be able to identify which panel the control is being dragged onto and then to reassign the control back to the main form using the PointToScreen() method. Is this even possible?
private static void _ctrlParent_DragOver(object sender, DragEventArgs e)
{
...
ctrl.Parent.Controls.Remove(ctrl);
ctrl.Parent = cthis;
cthis.Controls.Add(ctrl);
Control ctrlPanelContainer = getPanelContainerName(ctrl);
string strPanelContainerName = ctrlPanelContainer.Text;
int intPanelContainerX = ctrlPanelContainer.Left;
int intPanelContainerY = ctrlPanelContainer.Top;
Point pt_parent = new Point(intPanelContainerX, intPanelContainerY); Control panelContainer = ctrl.TopLevelControl.GetChildAtPoint(pt_parent);
strPanelContainerNameMouseUp = panelContainer.Name;
frmSolitaireMainForm frm = new frmMainForm();
ctrl.Parent.Controls.Remove(ctrl);
ctrl.Parent = cthis;
cthis.Controls.Add(ctrl);
string strCthisNew = cthis.Name;
Point NewLocation = cthis.PointToScreen(new Point(e.X, e.Y));
ctrl.Left = NewLocation.X;
ctrl.Top = NewLocation.Y;
ctrl.BringToFront();
...
}
modified on Sunday, February 10, 2008 4:26 PM
|
|
|
|
|
hello!
I need any article on the topic "Application/ Benifits or Advanteges of a Digital Dictionary".Please any one help me to search this topic at least five pages.
i'll b very thankfull.
my email id is: abdul_bu@yahoo.com
|
|
|
|
|
Don't double-post. It's rude. Read the forum guidelines.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
I am recreating a collectable card game and need to make the game easily updatable.
Each card has its own effects which i will have to write specific functions for and
the problem arises when new cards need to be added and the application will obviously
not have the functionality for them.
Could i somehow write a dll for each card including the new functions or add the new
functions to an existing dll, but then how would the app know about the new functions. As you can tell i have not got a clue
|
|
|
|
|
In a situation like this where it's impossible for the calling application to know what changes you are going to implement in the callee, you need to provide a standardised method for managing it. You ensure that the card actually handles all of the effects and knows how to call them in response to some stimulus from the calling application. Take a look for plug in articles on this site to get an idea as to how others have handled this in the past.
|
|
|
|
|
|