|
Tried this but did not work. See following post for why and a new question.
|
|
|
|
|
I think I figured out why I'm having the problem but I still can not figure a way around it yet.
FooIterator in an inner class so it can only acess list if list is a static attribute. So I made changes like so:
<br />
<br />
public object Current<br />
{<br />
get<br />
{<br />
<br />
return Foo.list[lastVisited].thisBar;<br />
<br />
}<br />
But when checking the degugger, when I load Foo.list is is fine. When I access it via the Iterator inner class it is empty.
I tried to get rid of the inner class and return the static list and that did not work.
What I need to do is immitate the Java Iterator but this seems impossible because of the static attribute contrate on inner classes.
|
|
|
|
|
The problem is more complex than I wrote here but I will show my solution to this problem.
Here is what we had.
Class Foo<br />
{<br />
protected static List<T> list;<br />
<br />
list = fill_it_up();
<br />
public class FooIterator : IEnumerator<br />
{<br />
protected int lastVisited;<br />
<br />
public FooIterator ()<br />
{<br />
lastVisited = -1;<br />
<br />
more enumeration code....<br />
}
The FooIterator was neede by other class to enumerate through the List<>. The inner class was not working because the List has to be static.
Class Bar is an object that contains 2 other objects.
Here is the change:
Class Foo<br />
{<br />
protected List<Bar> list;<br />
<br />
list = fill_it_up();
<br />
public class FooIterator <br />
{<br />
private List<Bar> list;<br />
public FooIterator (List<Bar> anotherList)<br />
{<br />
list = anotherList;<br />
}<br />
public IEnumerator<FeFiFoe> GetEnumerator()<br />
{<br />
foreach (Bar b in list)<br />
{<br />
yield return b.thisFeFiFoe;<br />
<br />
}<br />
}<br />
<br />
}
Hope this helps someone else.
|
|
|
|
|
I have an ActiveX control that is wrapped as an AxHost class. It draws an image when certain properties are input to it. Is there any way that I could draw that control to an image instead of on a form? I tried using this:
<br />
using System;<br />
using System.Drawing;<br />
using System.Runtime.InteropServices;<br />
using System.Windows.Forms;<br />
<br />
public class ControlPainter<br />
{<br />
private const int<br />
WM_PRINT = 0x317, PRF_CLIENT = 4,<br />
PRF_CHILDREN = 0x10, PRF_NON_CLIENT = 2,<br />
COMBINED_PRINTFLAGS = PRF_CLIENT | PRF_CHILDREN | PRF_NON_CLIENT;<br />
<br />
[DllImport("USER32.DLL")]<br />
private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, int lParam);<br />
<br />
public static void PaintControl(Graphics graphics, Control control)<br />
{
IntPtr hWnd = control.Handle;<br />
IntPtr hDC = graphics.GetHdc();<br />
SendMessage(hWnd, WM_PRINT, hDC, COMBINED_PRINTFLAGS);<br />
graphics.ReleaseHdc(hDC);<br />
}<br />
}<br />
and it paints everything besides the ActiveX control. Does anyone know how to do this?
|
|
|
|
|
|
I'm sorry, I forgot to mention that I am using Framework 1.1... I think DrawToBitmap is only a 2.0 method.
|
|
|
|
|
I am displaying a folder in my windows app. This is the functionality I am trying to achieve:
User can go to Options > Locations > Change Location > and tell the program what folder to watch. On clicking 'OK' button I want my form (that displays the folder content) to be refreshed so that we can view the recently assigned filder's content.
What is the best way to do it?
Thanks in advance.
Note: this.Refresh(); does not work, I am assuming it just re-paint the form on the screen instead of refreshing the contents.
|
|
|
|
|
Whatever code is populating the list of file names the first time, just clear out the list and call that same code again when they change the target folder and click the OK button. If you are yet to create the code which lists the files in a folder, check out the System.IO namespace for classes that will help you get that info.
Josh
|
|
|
|
|
Thanks for the reply. Sounds like this should do the trick.
Just one more quick question as to how can I call the same code again; since the Click button is on a different form?
Here is how I did it (if there is a better of doing it plz let me know) When user goes to menu Options > Locations > and click 'Change Location' I open a new form and capture user input and save the new folder path to the Properties.Settings.Default.Folder_Location
|
|
|
|
|
student_rhr wrote: Just one more quick question as to how can I call the same code again; since the Click button is on a different form?
Either expose that code as a static method in a utility class, or as a public (possibly static) method on the Form-derived class which currently contains it. That will allow any code in any file to use that same method.
Josh
|
|
|
|
|
This is how I have the method within the frmMain()
public partial class frmMain : Form
{
public TreeNode parentNode;
public TreeView treeView1;
public string folderLocation = Video_Watcer.Properties.Settings.Default.Folder_Location.ToString();
public int progress;
public frmMain()
{
InitializeComponent();
}
private void frmMain_Load(object sender, EventArgs e)
{
PopulateTreeView();
}
public void PopulateTreeView()
{
DirectoryInfo di = new DirectoryInfo(folderLocation);
treeView1.ImageList = imageList1;
parentNode = treeView1.Nodes.Add(di.Name.ToString());
StatusBarLabelFolderPath.Text = di.FullName.ToString();
SetParentNodeImage();
string CurrentFileName;
for (int i = 0; i <= di.GetFiles().GetUpperBound(0); i++)
{
FileInfo[] fi = di.GetFiles();
txtWatcherStatus.Text = txtWatcherStatus.Text + Environment.NewLine + fi[i].ToString();
CurrentFileName = fi[i].ToString();
SetFileNodes(CurrentFileName);
}
}
}
But I am not able to see any thing in frmOptions when I type frmMain. PopulateTreeView does not pop-up in the intellisense. what am I doing wrong here
This is the code for my frmOptions form:
private void btnApply_Click(object sender, EventArgs e)
{
try
{
Properties.Settings.Default.Folder_Location = txtFolderPath.Text.ToString();
Properties.Settings.Default.Save();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
|
|
|
|
|
frmMain is a class, not an instance of a class. Since the PopulateTreeView method is not static, then you can't call it without an instance of frmMain. Make the PopulateTreeView method static and alter the parameter list so that it accepts an instance of frmMain (to access the TreeView, StatusBar, etc.)
Josh
|
|
|
|
|
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
|
|
|
|