|
I want to place a MDI form at a certain position in relation to the MDI background application window.
Ie. When I display a certain form I would like to display the form on the right of the applications MDI window and locatthis child form in the top right corner.
How could I achieve this in c#.
|
|
|
|
|
In the Activate or Shown Event of the child form you could probably include code like the following:
this.Location = new Point(this.ParentForm.Width - (this.Width + 10), 0);
Of course, if you put the code in the Activate event you will want to ensure the code only executes the first time the form activates. That should get your MDI child in the ballpark of the right corner of the parent form. You might have to play around with the value you add to this.Width a little bit.
Good luck.
|
|
|
|
|
How can I know where a url gets redirected programatically?
e.g. This url:
http://scobleizer.com/feed/
redirects to the following url:
http://feeds2.feedburner.com/fastcompany/scobleizer
I am trying to read the xml document of feed. But the following lines of code:
var doc = new XmlDocument();
doc.Load(url);
will throw an exeption for the first url:
System.Net.WebException: The remote server returned an error: (404) Not Found.
|
|
|
|
|
Hey,
i want to generate a WM_DROPFILES Message and send it to a Control on my Form.
i found one sample in c++
http://groups.google.de/group/microsoft.public.platformsdk.shell/browse_frm/thread/5bbd1d67913ac2c7?hl=de&lr=&rnum=2&prev=/groups%3Fq%3Dsendmessage%2Bwm_dropfiles%26hl%3Dde%26lr%3D%26selm%3D03c301c3973d%25240433f8e0%2524a101280a%2540phx.gbl%26rnum%3D2
does anybody know how it sounds right in C# .Net 2.0?
here my trying, which doesnt work:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;
namespace DropFile
{
partial class Form1
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Vom Windows Form-Designer generierter Code
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
this.button1.Location = new System.Drawing.Point(341, 12);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(142, 40);
this.button1.TabIndex = 0;
this.button1.Text = "Load Image";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(860, 546);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.DragDrop += new System.Windows.Forms.DragEventHandler(this.Form1_DragDrop);
this.DragOver += new System.Windows.Forms.DragEventHandler(this.Form1_DragOver);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button button1;
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_DragOver(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] FileList = (string[])e.Data.GetData(DataFormats.FileDrop, false);
if (FileList.Length == 1)
{
FileInfo fi = new FileInfo(FileList[0]);
if (fi.Extension == ".gif" | fi.Extension == ".bmp" | fi.Extension == ".jpg" | fi.Extension == ".jpeg")
{
e.Effect = DragDropEffects.Move;
}
}
}
else
e.Effect = DragDropEffects.None;
}
private void Form1_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] FileList = (string[])e.Data.GetData(DataFormats.FileDrop, false);
if (FileList.Length == 1)
{
FileInfo fi = new FileInfo(FileList[0]);
if (fi.Extension == ".gif" | fi.Extension == ".bmp" | fi.Extension == ".jpg" | fi.Extension == ".jpeg")
{
this.BackgroundImage = Image.FromFile(FileList[0]);
}
}
}
else
e.Effect = DragDropEffects.None;
}
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
public const uint GMEM_FIXED = 0x0000;
public const uint GMEM_SHARE = 0x2000;
public const uint WM_DROPFILES = 0x0233;
[DllImport("Kernel32.dll", SetLastError = true)]
public static extern int GlobalLock(IntPtr Handle);
[DllImport("Kernel32.dll", SetLastError = true)]
public static extern int GlobalUnlock(IntPtr Handle);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32.dll", SetLastError = true)]
static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam,
IntPtr lParam);
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public Int32 X;
public Int32 Y;
public POINT(Int32 x, Int32 y)
{
this.X = x;
this.Y = y;
}
}
[Serializable]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
class DROPFILES
{
public int size;
public POINT pt;
public bool fND;
public bool WIDE;
}
public static byte[] RawSerialize(object anything)
{
int rawsize = Marshal.SizeOf(anything);
IntPtr buffer = Marshal.AllocHGlobal(rawsize);
Marshal.StructureToPtr(anything, buffer, false);
byte[] rawdatas = new byte[rawsize];
Marshal.Copy(buffer, rawdatas, 0, rawsize);
Marshal.FreeHGlobal(buffer);
return rawdatas;
}
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_DROPFILES)
{
bool bTest = true;
}
base.WndProc(ref m);
}
private void button1_Click(object sender, EventArgs e)
{
IntPtr hwnd = this.Handle;
DROPFILES s = new DROPFILES();
s.size = 20;
s.pt = new POINT(10, 10);
s.fND = false;
s.WIDE = false;
string file = "D:\\test.bmp\0";
Int32 filelen = Convert.ToInt32(file.Length);
byte[] bytes = RawSerialize(s);
int structlen = (int)bytes.Length;
int size = structlen + filelen + 1;
IntPtr p = Marshal.AllocHGlobal(size);
GlobalLock(p);
int i = 0;
for (i = 0; i < structlen; i++)
{
Marshal.WriteByte(p, i, bytes[i]);
Console.WriteLine("Wrote header byte " + i.ToString() + " of " + size.ToString());
}
byte[] b = ASCIIEncoding.ASCII.GetBytes(file);
for (int k = 0; k < filelen; k++)
{
Marshal.WriteByte(p, i, b[k]);
Console.WriteLine("Wrote filename byte " + i.ToString() + " of " + size.ToString());
i++;
}
Marshal.WriteByte(p, i, 0);
GlobalUnlock(p);
PostMessage(hwnd, WM_DROPFILES, p, IntPtr.Zero);
Marshal.FreeHGlobal(p);
}
}
}
thanks a lot
Steffen
|
|
|
|
|
May be you should add:
this.AllowDrop = true;
in
private void InitializeComponent()
|
|
|
|
|
Did you ever find the solution to this?
|
|
|
|
|
Hello everyone,
I am developing a Web Services based on ASP.Net asmx web service. The server end will response byte[] to client encoded in UTF-8, and client to convert the byte[] to string.
My confusion is, the England pound character at server side (I dump just before the Http response is wrote, and the character at server side is correct to be England pound) will be received as ?? from client side. I also used Fiddler at client side to monitor traffic on wire, the on wire traffic is correct to be pound.
Any ideas what is wrong? I suspect it is encoding issue, but I have no idea how to debug further and any settings (settings from client web service proxy?) which will impact?
thanks in advance,
George
|
|
|
|
|
Hi evryone
1. How can I show and print in CristalReport widthwise (in C# code) ?
2. How can I Make PDF file whith C# code ?
|
|
|
|
|
Short Answer: PdfWriter
string path = Path.GetTempPath() + Path.GetRandomFileName() + ".pdf";
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(path, FileMode.Create));
document.Open();
document.Add(new Paragraph("Karaoke Go!"));
iTextSharp.text.Font font5 = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 9);
PdfPTable table = new PdfPTable(dt.Columns.Count);
PdfPRow row = null;
float[] widths = new float[] { 6f, 6f, 1f };
table.SetWidths(widths);
table.WidthPercentage = 100;
int iCol = 0;
string colname = "";
PdfPCell cell = new PdfPCell(new Phrase("Karaoke Go"));
cell.Colspan = dt.Columns.Count;
foreach (DataColumn c in dt.Columns)
{
table.AddCell(new Phrase(c.ColumnName, font5));
}
foreach (DataRow r in dt.Rows)
{
if (dt.Rows.Count > 0)
{
table.AddCell(new Phrase(r[0].ToString(), font5));
table.AddCell(new Phrase(r[1].ToString(), font5));
table.AddCell(new Phrase(r[2].ToString(), font5));
}
} document.Add(table);
document.Close();
System.Diagnostics.Process.Start(path);
Cheers
|
|
|
|
|
|
I have 2 classes namely Client.cs and Server.cs
Each class has a main() method...
So it gives me an error:
More than one entry point
Can i call a class from another class in C#?
If so how can i do it?
|
|
|
|
|
You can never call a class, you can only call methods (ok and a few others things, too much detail..)
If they would be allowed to both have a Main, then which one would start? Should the program start out with 2 threads?
But, probably, you have 2 programs there that have to be run as 2 programs, because that's what they are. So put them in 2 different projects..
|
|
|
|
|
Actually each class may have its Main method. If you have more than one Main method you just have to specify your startup object (the class that contains the main which you want to start).
|
|
|
|
|
You're making it more complicated than it needs to be.
If you have a client and a server object, you don't want to start just one of them anyway.
|
|
|
|
|
No, I'm not.
I do have projects which could be separated into more projects but I do like to keep it simple in a solution. When I need it to run a just choose the startup object. This is working for me when doing throwaway test code, without the complexity of a new project.
|
|
|
|
|
This is pretty beginner stuff. You should google "object instantiation", "constructor" and so on.
|
|
|
|
|
how do i read the text inside the current running windows application?
|
|
|
|
|
I'm sorry, but we have no idea what you are talking about.
Maybe you can explain what is the problem, where the problem exist and maybe you can put some (SOME, not 2 pages of code) code in here to clearify what you mean.
If you explain the problem better, we will most probably give you anwsers.
|
|
|
|
|
i am sorry for the unclear posted question. now i would try to explain in detail. i havenot written much code yet. but my problem is, i have to read the EULA(Enduser Licence Agreement) text through my program while installing the .exe file.i do not know how could i access that.hope you would understand this and give ur advice to solve this.
|
|
|
|
|
So you are making an installer and you would like to read an EULA, as like a text file?
Use a stream reader for this problem.
|
|
|
|
|
thanks for your reply. see you soon with more douts
|
|
|
|
|
Dear All,
I am getting an embedResource Text File using following code, but when i want to write into it.
It gives me an error, "Stream does not support writting".
[code]
System.Reflection.Assembly ass=Assembly.GetExecutingAssembly();
System.IO.Stream s=ass.GetManifestResourceStream("testLogin.test.txt");
byte[] array=new byte[s.Length];
s.Read(array,0,Convert.ToInt32(s.Length));
//here i am writting
s.Write(myarray,0,myarray.Length); //the error is here
[/code]
The question is how can i make it read/write.
The file is embededResource.
Abdul Rahaman Hamidy
Database Developer
Kabul, Afghanistan
|
|
|
|
|
first i opened a form in windows application. later i added a crystal report to the application and added some information to the crystal report by using microsoft oledb provider for sqlbut it ishowing the error.the code iused there is
cust c =new cust();
crystalreportviewer1,reportsource=rpt;
it is showing an error like
Error 1 'crdemo1.cust' does not contain a definition for 'rpt'
|
|
|
|
|
Hi. I create a usercontrol. It's name is Imagelists and it holds images as a list. And it has indexer property as
public Image this[int i]
when i use it in an event as Imagelists1[2]. i want to see the second image name as a property. when i call Imagelists1[3].Name, let it returns me the name of image. But i couldn't see the Name property when i use it with it's indexer. if i don't use indexer an i use like ImageLists1.Name, i can see the Name property. I just want to see like Imagelists1[3].Name and it returns me the name of 3rd image. How could i do this?
|
|
|
|
|
Hello,
I have a problem in my application and I don't really know how to solve it:
unsafe public System.Collections.IEnumerator GetEnumerator()
{
char[] sString1 = new char[max];
for (int numer = 0; numer < roz; numer++)
{
fixed (char* sString = sString1)
{
for (int i = min; i <= max; i++)
{
string a = brute(sString, 2, sString1, numer);
yield return a;
}
}
}
}
private string brute(char* sString, int nLen, char[] sPoczatek, int num)
{
while (nLen > 0)
{
if (nLen == 1)
{
for (int i = num; i < zn.Length; i += roz)
{
sString[0] = zn[i];
brute(sString + 1, nLen - 1, sPoczatek, num);
}
}
else
{
for (int i = 0; i < zn.Length; i++)
{
sString[0] = zn[i];
brute(sString + 1, nLen - 1, sPoczatek, num);
}
}
}
return sPoczatek.ToString();
}
Error 1 Unsafe code may not appear in iterators
Is that possible to use GetEnumerator() with unsafe code?
111
modified on Sunday, February 22, 2009 11:38 AM
|
|
|
|
|