|
Well, this is what I tried (code below). However, the compiler says "Use of keyword 'base' is not valid in this context ". I thought that base was like this , but for accessing a parent class. How should I do it?
public class ReverseTrackBar : TrackBar
{
private new int Value
{
get { return (((TrackBar)base).Maximum - (((TrackBar)base).Value - this.Minimum)); }
set { ((TrackBar)base).Value = (((TrackBar)base).Maximum - ((int)value - this.Minimum)); }
}
private new int Maximum
{
get { return ((TrackBar)base).Maximum; }
set
{
int val = this.Value;
((TrackBar)base).Maximum = (int)value;
this.Value = val;
}
}
public ReverseTrackBar()
{
this.Value = 0;
}
}
-Daniel
Typing too fast fro my owngood
|
|
|
|
|
I guess the 'new' keyword is hiding the base value.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
No, that's not it. See the message I posted at the same time as you...
-Daniel
Typing too fast fro my owngood
|
|
|
|
|
Oh, I guess you don't have to cast base to a type because the type is already known (the type I'm inheriting from).
-Daniel
Typing too fast fro my owngood
|
|
|
|
|
Yes, I wondered about that
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Heritos Gger wrote: However, the compiler says "Use of keyword 'base' is not valid in this context".
The error is not related to the use of the keyword 'base', but to the fact that you try to cast the base to type TrackBar. You don't need to do that. Remove all of these casts (e.g. ((TrackBar)base).Value should be base.Value) and the compiler error will disappear.
|
|
|
|
|
|
I think the solution to your problem is this:
Hide the property of the base class, but make the access modifier the same as in the base class, i.e. public.
Next, add the modifier protected to the set-accessor (.NET 2.0 required). The get-accessor cannot be protected as well, but I don't think that's a problem, I fact I think it's good practice to keep the get-accessor accessable.
You'll get something like this:
public new int Value<br />
{<br />
get { return (base.Maximum - (base.Value - this.Minimum)); }<br />
protected set { base.Value = base.Maximum - (value - this.Minimum); }<br />
}
That should work.
|
|
|
|
|
Yes, that's close to what I ended up with.
The set accessor is fine to be public because I can perform the reversal of data right there. I just didn't want the "outside" to have access to the base class's Value and Maximum properties. All I needed to do was overload them with new , and now it works beautifully.
Thank you, everyone! Case closed.
-Daniel
Typing too fast fro my owngood
|
|
|
|
|
Hi
I just want to know, I am busy building a gallery websit, how do I by using c# in Visual Studio 2005 activate a button next to the picture to download the image to the users harddrive?
Please help.
Thanx.
Tiaan
|
|
|
|
|
You can't force a direct download, but you can give the user the option to download it.
Make a proxy page that sends the image as response with the content type application/octet-stream. The browser won't display it, but ask the user what to do with it.
---
b { font-weight: normal; }
|
|
|
|
|
Hi,
I sorted a txt file using an arraylist() which contains over 600 words.
I just don't know how to write them to a file. I tried a few things.
This is my code:
FileStream sortWords = File.Open(@"sortwords.txt", FileMode.Open, FileAccess.Read);
StreamReader reader = new StreamReader(sortWords);
ArrayList getLines = new ArrayList();
string linesForArray = null;
while ((linesForArray = reader.ReadLine()) != null)
{
getLines.Add(linesForArray);
}
getLines.Sort();
FileStream newDoc = File.Open(@"sortedList.txt", FileMode.Create, FileAccess.Write);
StreamWriter sw = new StreamWriter(newDoc);
Any suggestions how to write it to a text file?
Thanks in advance!
|
|
|
|
|
Use foreach to iterate over the strings and write them ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi Christian,
Thank you, that worked!
Why didn't i think of that :S
|
|
|
|
|
Question:
I want to pass in some custom key values from my web config. Been researchingan dcan not get get it to work. So do I need to set up a function that loops through my values in the web config?? Not sure.
Thanks in advance
-------------------------------------------------------------
Web Config:
<configuration>
<configSections>
<sectionGroup name="DirectoryInfo">
<section name="Common" type="System.Configuration.NameValueFileSectionHandler, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="OrgPaths" type="System.Configuration.NameValueFileSectionHandler, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</sectionGroup>
</configSections>
<DirectoryInfo>
<Common>
<add key="Root" value="C:\temp" />
</Common>
<OrgPaths>
<add key="name1" value="\folder1" />
<add key="name2" value="\folder2\folder2.1" />
</OrgPaths>
</DirectoryInfo>
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
My Page:
public void Execute()
{
//I Create a Directory object using DirectoryInfo
string mydir = (@"C:\Temp\folder1");//I WANT THIS PASSED IN FROM THE
//WEBCONFIG?
DirectoryInfo dir = new DirectoryInfo(mydir);
//Pass the Directory for displaying the contents
getDirsFiles(dir);
}
|
|
|
|
|
Where can i get the Visual studio 2005 download online plz?
.
|
|
|
|
|
Google broken where you live ?
You can download the express edition, but any other edition is what we like to call stealing.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
What is a good way to implement a tree view search where using wild card is possible?
|
|
|
|
|
Pretty generic question...
You have to traverse the tree and for each node find out if the node matches the seach criteria.
You can read about tree treversal on wikipedia[^], for example. They mainly disuss binary trees there, but you can easily adjust for nodes having more than 2 children.
For the comparison you could use a regular expression and test each tree node's text if it matches the expression.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Hi,
So here's something I hadn't considered when I started developing my application about a year ago. It now has dozens of screens, and for just about all of them the graphics turn out wrong when I change my DPI settings from 96dpi to 120dpi. I've read some MS articles on this, but they basically state "rewrite your UI code".
Since this could take months I'm wondering if there's any way to map my pixel-based scaling to take the dpi-setting into account, or any other solution. Do any of you have experience in this? Is there anyone that has a fix or a suggestion for this that doesn't come down to "rewrite your code"? Any help would be greatly appreciated!
|
|
|
|
|
Hi all
I get points(x,y coordinates) delivered from a external source via Bluetooth. I want to draw these points(strokes) in real-time in an PowerPoint presentation. Each stroke shall be an object in PowerPoint so the user then can move around the free hand drawing stroke after the entire stroke is finished.
The problem I have is that the actual object that appears in PowerPoint when drawing flickers a lot because of up to 75 new points per second can be received. Is there any way of do this in a better way? Or should I just store up points and then update to PowerPoint in intervals?
Any help is much appreciated as there is hard to find any good information or tutorials about the best way to interface with powerpoint...
Kind Regards
Jonas Olofsson
Code snippet:
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
public void UpdateFreeDrawStroke(int x, int y)
{
// Update active free draw stroek with new point
currentStroke.Nodes.Insert(currentStroke.Nodes.Count, Microsoft.Office.Core.MsoSegmentType.msoSegmentLine, Microsoft.Office.Core.MsoEditingType.msoEditingAuto, ConvertCoord(x), ConvertCoord(y),0,0,0,0);
}
// Create new active free draw stroke at (x,y)
public void NewFreeDrawStroke(short x, short y)
{
int convX = ConvertCoord(x);
int convY = ConvertCoord(y);
PowerPoint.FreeformBuilder b = pptSlide.Shapes.BuildFreeform(Microsoft.Office.Core.MsoEditingType.msoEditingAuto, convX, convY);
b.AddNodes(Microsoft.Office.Core.MsoSegmentType.msoSegmentLine, Microsoft.Office.Core.MsoEditingType.msoEditingAuto, convX+1, convY+1, 0, 0, 0, 0);
currentStroke = b.ConvertToShape();
}
|
|
|
|
|
Hi there, i get an exception while using C# and wmi to retrieve some data.
So here is the code is wrote:
<br />
public class Adapter<br />
{<br />
public static ManagementObjectCollection GetNicAdapters()<br />
{<br />
try<br />
{<br />
WqlObjectQuery WQO = new WqlObjectQuery("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionStatus != null");<br />
ManagementObjectSearcher MOS = new ManagementObjectSearcher(WQO);<br />
ManagementObjectCollection MOC = MOS.Get();<br />
return MOC;<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show("Data couldn't be retrieved.");<br />
return null;<br />
}<br />
}<br />
I use this function to populate a field in my Form1 Base form. On the form (visually) there is a combo box, which now is filled with the Description of the Object.
All of this works so far but now i am getting problems:
<br />
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)<br />
{<br />
<br />
if (Adapters != null)<br />
{<br />
try<br />
{<br />
ManagementObject[] MOArray = new ManagementObject[Adapters.Count];<br />
Adapters.CopyTo(MOArray, 0);<br />
<br />
int select = comboBox1.SelectedIndex;<br />
int selectedIndex = int.Parse(MOArray[select]["Index"].ToString());<br />
int status = int.Parse(MOArray[select]["NetConnectionStatus"].ToString());<br />
<br />
string myQueryString = "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE Index = " + selectedIndex.ToString();<br />
<br />
WqlObjectQuery ConfigQuery = new WqlObjectQuery(myQueryString);<br />
ManagementObjectSearcher ConfigSearcher = new ManagementObjectSearcher(ConfigQuery);<br />
ManagementObjectCollection ManagementObjectConfigurations = ConfigSearcher.Get();<br />
<br />
ManagementObject[] CurrentArray = new ManagementObject[ManagementObjectConfigurations.Count];<br />
<br />
ManagementObjectConfigurations.CopyTo(CurrentArray, 0);<br />
ManagementObject CurrentConfig = CurrentArray[0];<br />
<br />
#region Draw Status<br />
IconConverter IC = new IconConverter();<br />
switch (status)<br />
{<br />
case 0:<br />
l_status.Text = "Gerät nicht angeschlossen";<br />
pb_status.Image = (Image)IC.ConvertTo(Switch.Properties.Resources.status_disconnected, typeof(Image));<br />
break;<br />
}<br />
#endregion<br />
<br />
l_MAC.Text = CurrentConfig["MACAddress"].ToString();<br />
l_host.Text = CurrentConfig["DNSHostName"].ToString();<br />
l_svc.Text = CurrentConfig["ServiceName"].ToString();<br />
<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show(ex.ToString());<br />
}<br />
}<br />
Executing the code i get a NullReferenceException where it says:
l_MAC.Text = CurrentConfig["MACAddress"].ToString();
So why is the MACAddress Property not set? It seems to be that the second wql query isn't working, but why? please help me i am soooo close to loosing it and throwing my laptop out of my window!
please rescue me.thanx in advance.
|
|
|
|
|
Hi,
is there a way to make a property from a base class like "BackColor" protected or private in the derived class?
I want to make a ThinButton inherited from the button class and don't want to see BackColor in the propertygrid..
Thx
Kurt
|
|
|
|
|
You can't change its visibility, but you can use the System.ComponentModel.BrowsableAttribute to hide it from the property grid.
|
|
|
|
|
Great..gonna try this one.
thx for the quick response..
Kurt
|
|
|
|