|
Thanks a lot for helping me with this problem, but as you can see I am just a beginer in C#, I was not entirely sure as to how I am suppose to alter the parameter list. Did you ask me to do something like PopulateTreeView(object frm) or something like PopulateTreeView(TreeView tv, StatusBar, SB) ?? or neither?? if neither then a code example will really be helpful (if at all possible)
your replies are much appreciated
|
|
|
|
|
You may ignore my last post
I changed the code to following:
public static void PopulateTreeView(frmMain d)
{
DirectoryInfo di = new DirectoryInfo(d.folderLocation);
d.treeView1.ImageList = d.imageList1;
d.parentNode = d.treeView1.Nodes.Add(di.Name.ToString());
d.StatusBarLabelFolderPath.Text = di.FullName.ToString();
d.SetParentNodeImage();
string CurrentFileName;
for (int i = 0; i <= di.GetFiles().GetUpperBound(0); i++)
{
FileInfo[] fi = di.GetFiles();
d.txtWatcherStatus.Text = d.txtWatcherStatus.Text + Environment.NewLine + fi[i].ToString();
CurrentFileName = fi[i].ToString();
d.SetFileNodes(CurrentFileName);
}
}
And frmMain_Load call to following:
private void frmMain_Load(object sender, EventArgs e)
{
PopulateTreeView(this);
}
But the contents have not been updated, I must be doing something wrong here.
|
|
|
|
|
This doesn't really make any sense. If you need a reference to the frmMain instance so that you can pass it as a parameter, you might as well just make the method non-static and not take in a parameter of type frmMain (it would reference the fields via this instead of the parameter).
Basically what you want to do is make the logic which refreshes the list of items in a folder publicly available so that any other form can call that method on a myForm instance. It only makes sense to have it be static if it is a method contained in a completely different class.
Josh
|
|
|
|
|
Josh Smith wrote: Make the PopulateTreeView method static and alter the parameter list so that it accepts an instance of frmMain (to access the TreeView, StatusBar, etc.)
.
This is what I was trying to do. Did you mean that I need to put the PopulateTreeView method is a seperate class and pass it an instance of frmMain?
I guess the problem is my lack of knowldge, if you would be so kind to provide a code example that would really be helpful. Thanks.
Best Regards,
rhr
|
|
|
|
|
You just need to understand how instances work. It's central to object oriented programming.
class frmMain
{
...
public PopulateTreeView()
{
}
}
frmMain mainInstance = new frmMain();
frmMain.PopulateTreeView();
Now, that creates a new instance of frmMain. If you want to use an existing instance, you'll just need to pass that instance into the calling code.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Is Jesus the Jewish Messiah?
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
I wasn't vouching for one particular implementation (whether it be a static method in a utility class, an instance method in frmMain, etc.) All I was saying is that if you want the user to be able to perform the same action from two different places in the GUI (i.e. populate the list of files in a folder) then you should consolidate that shared logic into a single method. Then have all locations which require that functionality call into that one method. Since, as far as I can tell, your app has one place which displays the files but multiple places that trigger the population of the list, it makes sense to expose the list population code in the form which contains the list.
Pseudo-code example:
class MainForm : Form
{
private void frmMain_Load( object sender, EventArgs e )
{
this.PopulateList( @"C:\ognac\Is\Yummy" );
}
public void PopulateList( string folderPath )
{
}
}
class SomeOtherForm : Form
{
private MainForm mainForm;
public SomeOtherForm( MainForm mainForm )
{
this.mainForm = mainForm;
}
public void btnWhatever_Click( object sender, EventArgs e )
{
this.mainForm.PopulateList( @"A:\rmagnac\Is\Yummy" );
}
}
Josh
|
|
|
|
|
Hi,
I'm trying to draw a focus rectangle on a button, since, when I load a tabpage, if the first control on that page is a button, it doesn't highlight and you can't tell that it has focus.
So I stumbled across the ControlPaint.DrawFocusRectangle command and put this in after loading the rest of the page:
int x = button2.ClientRectangle.Location.X + 3;<br />
int y = button2.ClientRectangle.Location.Y + 3;<br />
int w = button2.ClientRectangle.Width - 6;<br />
int h = button2.ClientRectangle.Height - 6;<br />
Rectangle r = new Rectangle(x,y,w,h); ControlPaint.DrawFocusRectangle(Graphics.FromHwnd(button2.Handle), r, Color.Red, Color.Red);
But I get nothing.
Then I added a paint event for the button and moved the code there, although instead of saying Graphics.FromHwnd(button2.Handle) , I said e.Graphics . Now it worked, but I'm not able to move away from the button using the up/down arrows. If I throw a messagebox in, after I click the OK button, I can move around without trouble. It seems to have something to do with returning control to the system. Is there anything I can say to give control back to the system? Or am I doing stuff completely wrong?
Thanks so much for any thoughts!!!!!!
Mel
-- modified at 12:18 Monday 1st May, 2006
|
|
|
|
|
Why don't you just call the button's Select method in the form Load handler, and then set the form's ActiveControl to the button? That will select the button and give it a focus rect.
Josh
|
|
|
|
|
I am working on an app that allow users to view training videos from a web interface(they can download it from an intrAnet webpage).
Would it be a good idea to store the video files (typically over 70MB) into a DataBase for better Management and Organization. Or should they be on FileSystem and only tags (Such as Name, MimeType, Size, Created Date etc) be stored in the DataBase?
Thanks in advance.
|
|
|
|
|
student_rhr wrote: Would it be a good idea to store the video files (typically over 70MB) into a DataBase
No!! You'll bog down the database because you have to constantly unpack the thing so the users can see it. Keep them on the server as seperate files and put the link in the database.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hi,
Currently I am working on a windows application, and one of my form has to be a system modal type. In good old VB the option was available, but now in C# with .NET framework its not there.
If any one can help me out here and give me some guidence with how to make windows .NET form a system modal type?
My Reauirements are :
The form has to be on top all the time.
No Minimizations allowed.
Cannot switch to any other application.
Can not open windows explorer or press ctrl+alt+delete.
Thanks
Lav Pathak
Application Developer
Auxiliary Enterprises
Kalamazoo, MI
|
|
|
|
|
Calling ShowDialog on a Form-derived class will show it modally. It will be on top of all other windows in your app. If you set the form's MinimizeBox property to false, you won't be allowed to minimize the dialog.
Lav Pathak wrote: Cannot switch to any other application.
Can not open windows explorer or press ctrl+alt+delete.
These features are not available in WinForms. You might be able to use some Win32 calls to accomplish those.
Josh
|
|
|
|
|
Josh thanks for the quick reply, but i need to keep my form on top of all the other apps. I know this is a bad design, but i dont have many options here.
I Dont know what win32 calls i shuold make to make it system wide modal.
Thanks
Lav Pathak
Application Developer
Auxiliary Enterprises
Kalamazoo, MI
|
|
|
|
|
Lav Pathak wrote: I Dont know what win32 calls i shuold make to make it system wide modal.
Me neither.
|
|
|
|
|
Apparently[^], MS doesn't want us to create system modal dialogs.
I tried adding the DS_SYSMODAL style to the underlying Win32 window when the form is initialized, but that didn't work. See below:
private void OnLoad(object sender, EventArgs e)
{
Int32 nStyle = GetWindowLong (this.Handle, (-16));
nStyle |= 0x02;
nStyle = SetWindowLong (this.Handle, (-16), nStyle);
}
[DllImport("User32.dll", SetLastError=true)]
private static extern Int32 GetWindowLong
(IntPtr hWnd, int nIndex);
[DllImport("User32.dll", SetLastError=true)]
private static extern Int32 SetWindowLong
(IntPtr hWnd, int nIndex, Int32 nNewStyle);
I then resorted to this (extremely) cheesy solution which works:
public Form1()
{
InitializeComponent ();
Timer timer = new Timer();
timer.Interval = 1;
timer.Tick += new EventHandler (timer_Tick);
timer.Start();
}
void timer_Tick(object sender, EventArgs e)
{
this.TopMost = true;
this.Activate();
}
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Ravi Bhavnani wrote: Apparently[^], MS doesn't want us to create system modal dialogs.
I largely agree, and always ontop *option* can be useful in limited circumstances but not as a modal. For any application I'm using my reaction to that sort of behavior would be task manager-kill process. I can see the desire to do something like this for a kiosk type app, but full screen and eating alt-tab, and ctrl-alt-del would be the stronger solution there unless you're using hardware with a nuetered keyboard that can't enter those strokes.
|
|
|
|
|
|
Hi,
In my C# application I am trying to execute a SQL query, transform the query results (using XSL) returned in a form of XML, and ultimately want the resutlset as a string in resultSetToAscii. I have started working on C# very recently, so I am sure that I am doing some silly mistake. Basically my code fails in the 3rd line here and the error desc is "Data at root level is invalid". Anybody any ideas?
XPathDocument destination;
XPathDocument source;
source = new XPathDocument(new StringReader("//row"));
destination = new XPathDocument(_xsl.Transform(source, null, (XmlResolver)null));
XPathNavigator nav = destination.CreateNavigator();
{
XPathNodeIterator iterator = nav.Select("//row");
while (iterator.MoveNext())
{
foreach (Field field in _destinationFields)
{
string data = "";
if (field.name != null)
data = iterator.Current.GetAttribute(field.name, String.Empty);
resultSetToAscii = data.PadRight(field.size, ' ');
}
}
}
|
|
|
|
|
You are creating a StringReader for the string "//row" and try yo use that as an xml document. The problem is that "//row" is far from a valid xml document.
Are you trying to use xpath to read nodes from an xml document? Then you actually have to have an xml document to read from...
---
b { font-weight: normal; }
|
|
|
|
|
Okay I understand. I think the resultset is in the form of xml. I get the resultset by executing this int iRecs = cmd.ExecuteNonQuery();
So what can I pass to this call below?
source = new XPathDocument(...)
Thanks.
|
|
|
|
|
The ExecuteNonQuery doesn't return a result, it only returns the number of records affected by the query. So, you don't have any data to start with.
---
b { font-weight: normal; }
|
|
|
|
|
After reading bytes of a file, if I check
ex) file[0]==0xFE && file[1]==0xFF
and the condition is true, I can say that it is encoded in 'BigEndianUnicode'.
but how do I determine encoding of a file if the file has, say, 'Portuguese(DOS)-codepage 860' as an example.
Encodings other than obvious ones like UTF-8, BigEncidnaUnicode, or ASCII, how do I determine the encodings by reading bytes of the file? Is there any efficient way to check the encoding of a file?
|
|
|
|
|
If the file doesn't contain an encoding string no. MS has developed a statistical guessing engine for IE using byte frequencies that works most of the time, but afaik they've never released a way for 3rd party devs to use it.
|
|
|
|
|
Do you mean there is no way of user knowing what encoding a file has?
|
|
|
|
|
No, there is no way of determining what it is without guesswork.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|