|
You can control word from C# code. Word can save and load RTF and can save HTML, so you could load a RTF and save as HTML, by using the Microsoft tools for office to control Word on the client machine.
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
Christian Graus wrote: by using the Microsoft tools for office to control Word on the client machine.
What do we search to find the reference about it ?
Freshman
|
|
|
|
|
|
Thank you Luc .
Regards.
Freshman
|
|
|
|
|
Hi All,
How to Append images and text in RichText Box .Thanks In Advance.
|
|
|
|
|
|
Hi everybody!
How to elegantly give the same effect as
Element last = getLastElementOfType<typeof(elem)>();
should give, but seems not to work? Without using reflection of course.
elem is an object of a type which derives from Element , but the type itself is unknown as it is passed to the method just as an Element.
I solved it by a switch statment which cases are all types deriving from Element , but it is ugly because it needs to be modified everytime a new derivative class is created.
Thanks in advance.
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
modified on Sunday, July 6, 2008 7:03 AM
|
|
|
|
|
|
There is no generic class here. There is a generic method only. Sorry for bad title.
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
I am not really sure what you are trying to do
Sounds to me like a visitor pattern, but I am not sure how generics will fit in. Maybe supply some more detail, and we can solve the problem
|
|
|
|
|
Situation has changed, because it turned out that different types requiere different methods, so a bunch of "is" cases was needed anyway.
But the subject is interesting, so assuming that I need the same thing which I needed before, the situation comes out as follows.
Let be an Element class and a set A of n XElement classes deriving from Element .
Let be a sequence of objects s and for each object o in s { type of o is in A }.
Let be a method M(start, end) .
Let be a function f(o) which returns some data related to an object o from sequence s.
The method M iterates through a part [start,end] of s and needs some information of every element o. So it calls function f(o) for each o in s. f is defined as follows:
internal T lastElementOfType<T>(int start) where T : Element
{
int index = elements.FindLastIndex(start, el => el is T);
return index == -1 ? null : (T)elements[index];
}
internal T lastElementOfType<T>(Element start) where T : Element
{
return lastElementOfType<T>(findIndex(start));
}
int findIndex(Element element)
{
return elements.FindIndex(el => object.ReferenceEquals(el, element));
}
Now.
In the implementation, s is a list of Element s, but objects of this list aren't of type Element but of one of types from A (from the definition of s given above). So I made f generic method which takes typeof(o) as a generic parameter. Unfortunately, passing an expression typeof(o) as T generates a compilation error. This is reasonable because typeof is evaluated at runtime. So what to do?*
* - I've got some ideas but I don't want to be a killjoy you know.
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
gajatko wrote: I've got some ideas but I don't want to be a killjoy you know.
Interesting problem, but I am not sure I understand completely. Sometimes generics are not worth it IMO
|
|
|
|
|
Hi,
I've been able to generate RSA key pair, and exporting them to XML files, (thanks to tutorials found in this forum)
The problem I'm facing is that I want to send the public key via socket communication to another server.
I will then use the public key to encrypt a password, which will be use for symmetric encryption communication between the two hosts.
I try sending the xml file, but I cannot seem to be able convert back to XML in the other end.
so then I thought if I could send the public key as a "string" which I could just load on the other end.
is this possible?
or is there a better way to share this "password key" for symmetric encryption.
Sorry if this is simple, I'm completely new to c# and programming.
Thanks,
JC
|
|
|
|
|
I am just starting to learn about creating custom controls using the book "GDI+ Custom Controls with Visual C# 2005". I am a little confused about overriding the control's OnPaint function. As a test, I created a custom control that has just a label. I then created the following code:
protected override void OnPaint(PaintEventArgs e)
{
}
I figured that since I am not calling the base.OnPaint(e), that the label would not get displayed, however when I run this, the label still shows up. Can someone explain why overriding a custom control and not calling base.OnPaint(e) does not effect and controls that are part of the custom control?
|
|
|
|
|
When you create a label control, a new window is created and as every window it's receiving it's own messages from the main message loop, including the paint message. A method Label.OnPaint is not invoked from the UserControl.OnPaint . It's called by Control.WmPaint(ref Message m) , which is called by (...), which is called by Application.ThreadContext.RunMessageLoop(int reason, ApplicationContext context) .
Try to make a "user control", which derives from Label , like this:
class MyControl : Label
{
...
override OnPaint { }
}
Then the label will not be drawn.
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
Hi, i got a Main form which is called FrmMain and the IsMDIContainter is set to true;
When the application is executed, the Form_load i got this code
FrmLogin childLogin = new FrmLogin();
childLogin.ShowDialog(this);
and my constructor i got
public FrmMain()
{
InitializeComponent();
allData = new AllData();
}
this is my AllData.cs
public class AllData
{
private Hashtable ht;
public AllData()
{
ht = new Hashtable();
}
}
Inside my FrmLogin constructor i got
public FrmLogin()
{
InitializeComponent();
staff = new Staff("Admin", "S123456I", "pass123", "13 April 1988", "ADDRESS", 91234567, 61234567, true, true, false, true);
}
how do i add the staff to my hashtable which is declare in the main form?
|
|
|
|
|
|
Inside my FrmMain (parent)
I have this
public Hashtable staffTable;
public FrmMain()
{
InitializeComponent();
staffTable = new Hashtable();
}
And inside my FrmLogin (child)
private FrmMain ParentForm;
private Staff staff;
public FrmLogin()
{
InitializeComponent();
staff = new Staff("Admin", "S123456A", "pass123", "13 April 1988", "ADDRESS", 912346678, 12345678, true, true, false, true);
((FrmMain)ParentForm).staffTable.Add("S8812466I", staff);
}
When the application is run, i get this error
"NullReferenceException was unhandled"
Object reference not set to an instance of an object.
modified on Sunday, July 6, 2008 6:26 AM
|
|
|
|
|
In FrmLogin create a delegate/event/event method, and a public class that inherits from EventArgs. In FrmMain, after FrmLogin is insanciated (but before it's shown), subscribe to the event in FrmLogin. Then, FrmLogin can raise the event and pass the Staff object in the eventargs, which will be received by FrmMain because it's listening for it.
Dave
|
|
|
|
|
Omg. erm i am new to C#, can u make it a little simpler?
probably u can give me some example?
modified on Sunday, July 6, 2008 7:48 AM
|
|
|
|
|
There's plenty of examples around - I've coded up a quick one below (needs much improvement but a starter).
frmMain:
using System;
using System.Windows.Forms;
namespace EventSample
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}
private void frmMain_Shown(object sender, EventArgs e)
{
frmLogin loginForm = new frmLogin();
loginForm.StaffLogin += new OnStaffLogin(loginForm_StaffLogin);
loginForm.ShowDialog();
loginForm.Dispose();
}
void loginForm_StaffLogin(object sender, LogInEventArgs e)
{
MessageBox.Show("Staff logged in: " + e.Staff.Name);
}
}
public class Staff
{
private string m_Name;
public string Name
{
get { return m_Name; }
set { m_Name = value; }
}
public Staff(string name)
{
m_Name = name;
}
}
}
frmLogin (with button1 added):
using System;
using System.Windows.Forms;
namespace EventSample
{
public delegate void OnStaffLogin(object sender, LogInEventArgs e);
public partial class frmLogin : Form
{
public event OnStaffLogin StaffLogin;
public frmLogin()
{
InitializeComponent();
}
private void FireStaffLogin()
{
StaffLogin(this, new LogInEventArgs(new Staff("Staff name goes here!")));
}
private void button1_Click(object sender, EventArgs e)
{
if (StaffLogin != null)
{
FireStaffLogin();
}
Close();
}
}
public class LogInEventArgs : EventArgs
{
private Staff m_Staff;
public Staff Staff
{
get { return m_Staff; }
set { m_Staff = value; }
}
public LogInEventArgs(Staff staff)
{
m_Staff = staff;
}
}
}
Dave
|
|
|
|
|
why does it look so complicated. LOL.. okay i show u more of my code probably u got a simpler way.
FrmMain
namespace EBMS
{
public partial class FrmMain : Form
{
public Hashtable staffTable;
public FrmMain()
{
InitializeComponent();
staffTable = new Hashtable();
}
private void FrmMain_Load(object sender, EventArgs e)
{
this.toolStripStaff.Visible = false;
this.toolStripCatalogue.Visible = false;
this.toolStripOrder.Visible = false;
this.toolStripInventory.Visible = false;
this.toolStrip.Enabled = false;
FrmLogin childLogin = new FrmLogin();
childLogin.ShowDialog(this);
if (childLogin.DialogResult == DialogResult.OK)
{
this.toolStripStaff.Visible = true;
this.toolStripCatalogue.Visible = true;
this.toolStripOrder.Visible = true;
this.toolStripInventory.Visible = true;
this.toolStripLogin.Visible = false;
this.toolStrip.Enabled = true;
stripLblLoginAs.Text = "Login As : " + childLogin.Username;
}
}
as u can see inside the constructor of FrmMain(), i have created an instance of the hashtable called 'staffTable'
FrmLogin
namespace EBMS
{
public partial class FrmLogin : Form
{
public FrmMain ParentForm;
private Staff staff;
public FrmLogin()
{
InitializeComponent();
staff = new Staff("Admin", "S123456I", "pass123", "13 April 1988", "address", 12345678, 12346567, true, true, false, true);
((FrmMain)ParentForm).staffTable.Add("S123456I", staff);
}
as u can see my FrmLogin last line of code, it will call the instance (staffTable) that is created in FrmMain when it loaded
Staff.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace EBMS
{
public class Staff
{
private string name;
private string nric;
private string password;
private string dob;
private string address;
private uint mobile;
private uint home;
private bool catManager;
private bool inventManager;
private bool orderManager;
private bool administrator;
public Staff(string name, string nric, string password, string dob,
string address, uint mobile, uint home, bool catManager, bool inventManager,
bool orderManager, bool administrator)
{
this.name = name;
this.nric = nric;
this.password = password;
this.dob = dob;
this.address = address;
this.mobile = mobile;
this.home = home;
this.catManager = catManager;
this.inventManager = inventManager;
this.orderManager = orderManager;
this.administrator = administrator;
}
public string Name
{
get { return name; }
}
public string NRIC
{
get { return nric; }
}
public string Password
{
get { return password; }
}
public string DOB
{
get { return dob; }
}
public string Address
{
get { return address; }
}
public uint Mobile
{
get { return mobile; }
}
public uint Home
{
get { return home; }
}
public bool CatManager
{
get { return catManager; }
}
public bool InventManager
{
get { return inventManager; }
}
public bool OrderManager
{
get { return orderManager; }
}
public bool Administrator
{
get { return administrator; }
}
}
}
|
|
|
|
|
I'm watching the F1 grand prix at the moment - will have a look at your code afterwards!
Dave
|
|
|
|
|
Doing it this way, the only way is to pass the hashtable to FrmLogin by overloading the constructor
FrmLogin:
private Hashtable staffTableFromMain;
public FrmLogin(Hashtable staffTable)
{
InitializeComponent();
staffTableFromMain = staffTable;
} You can then add to the table (as it's passed by reference) directly from fmLogin.
Edit: You'll need to change the line where you create the instance of FrmLogin in FrmMain as well of course!
FrmLogin childLogin = new FrmLogin(staffTable);
It's not the best way though. FrmLogin has no need to know about the staff table and really shouldn't be altering it. Also, imagine if there were other objects apart from frmMain that needed to know that the staffTable had changed... you would have no way to inform them. Thats's what events are for.
Examine the code I gave you before and read up on custom Events and Delegates. It is a far better way to do it and no so difficult when you get your head around it.
Dave
modified on Sunday, July 6, 2008 10:26 AM
|
|
|
|
|
the code u gave me before can be done??
could you give me 1 example based on my code? so sorry to trouble you..
why cant i just cast it to mainform then get the staffTable from there? thought it should work?
modified on Sunday, July 6, 2008 10:56 AM
|
|
|
|
|