|
Hi,
You can try :
float nwidth = (float)ImageBW8.Width / (float)ImageBW8.ImageWidth;
float nheight = (float)ImageBW8.Height / (float)ImageBW8.ImageHeight;
|
|
|
|
|
if those properties are integers, you get integer division.
And if 0 < Width < ImageWidth , you would get zero for nwidth.
You assigning the quotient to a float variable does not influence how an expression gets evaluated.
|
|
|
|
|
I’m apparently trying to do something stupid, because the C# help file says that I can’t, and that usually means my design is all jacked up.
Here’s a version of what I’m trying to do:
I have a base class, ItemBase, and I want to give it the method
public class ItemBase
{
public abstract static List<string> GetAvaliableUpgrades();
}
Then, I have three classes
public class Car : ItemBase { }
public class Van : ItemBase { }
public class Truck : ItemBase { }
(they implement GetAvaliableUpgrades())
And finally, I have a control
public class MyItemDisplay<T> : UserControl where T : ItemBase
{
public void SetUpgrades()
{
foreach (string s in T.GetAvaliableUpgrades())
listBox1.Items.Add(s);
}
}
Now I know that I can’t do that in C#, but I’m wondering if there is another way to implement this type of process. Since the Upgrades List is a property of the class itself and not unique to each instance, I want to make the GetAvaliableUpgrades() method static, and I don’t want to repeat myself, so I want the SetUpgrades() method in the Control to work on any ItemBase.
I know I can make something similar work by doing:
public class ItemBase
{
protected abstract List<string> GetMyUpgrades();
public static List<string> GetAvaliableUpgrades<T>() where T : ItemBase, new()
{
T item = new T();
return item.GetMyUpgrades();
}
}
public class MyItemDisplay<T> : UserControl where T : ItemBase
{
public void SetUpgrades()
{
foreach (string s in ItemBase.GetAvaliableUpgrades<T>())
listBox1.Items.Add(s);
}
}
But that feels sloppy and incorrect, since I’ve got to make an instance of a class to get a property about that class. Is there some kind of design pattern I can research that will allow me to get the kind of functionality that I’m looking for in C#? Or is there another way to allow me to have one control that works on a family of classes, without having to copy-paste a bunch of code? Thank you all in advance for your time!
Matt
|
|
|
|
|
Right, statics can't be polymorphic so they can't be abstract.
How will you get the upgrades? Are they plug-ins? Maybe you need an upgrade manager class?
|
|
|
|
|
I was going to have each class that : ItemBase have it hard coded, or maybe load from a file. My ultimate goal is to be able to create class AnyNewItem : ItemBase that I can just drop in to my program and will work with MyItemDisplay<T> : UserControl where T : ItemBase without me having to modify MyItemDisplay<T>.
Again, I could make the GetAvaliableUpgrades() non-static, but it doesn't feel right since the Upgrades are a propery of the class itself and not any specific instance.
Any ideas? =/
Thanks in advance,
Matt
|
|
|
|
|
I wonder if having Car, Van, Truck (etc.?) as distinct C# types is the root of the problem.
What would be the pros & cons of having a simple Vehicle class (and, probably, you would no longer need an ItemBase class)?
Here's how I might implement Vehicle:
public enum VehicleType { Car, Van, Truck }
class Vehicle
{
public VehicleType VehicleType { get; set; }
static private readonly Dictionary<VehicleType, List<string>> _availableUpgrades = new Dictionary<VehicleType, List<string>>();
public static List<string> GetAvailableUpgrades(VehicleType vehicleType)
{
if (!_availableUpgrades.ContainsKey(vehicleType))
throw new ArgumentException("Vehicle type " + vehicleType + " not recognized in upgrades collection.");
return _availableUpgrades[vehicleType];
}
}
If you absolutely must have distinct classes for each vehicle type, perhaps this would work:
class ItemBase
{
static private readonly Dictionary<Type, List<string>> _availableUpgrades = new Dictionary<Type, List<string>>();
public List<string> GetAvailableUpgrades()
{
Type myType = GetType();
if (!_availableUpgrades.ContainsKey(myType))
throw new ArgumentException("Vehicle type " + myType.Name + " not recognized in upgrades collection.");
return _availableUpgrades[myType];
}
}
class Car : ItemBase
{
}
|
|
|
|
|
public class MyItemDisplay<T> : UserControl where T : ItemBase{
public T ItemBase{
get;
set;
}
}
|
|
|
|
|
Hello!
Today i try write my own Music Player in C# - winmm.dll, but I don't know, how to go to next song, when last is end.
My Aplication:
Button1. Load music.
Button2. Add address from textBox, to listbox.
Button3. Stop playing.
And all work, when i add my music to playlist, and click on selected address, music start. But:
- How i can go to next song, when last end?. Because now, when song is end, player no start play next song.
Eg:
Music1
Music2
Music3
Music4
Eg.
- When I click on Music2 it starts to play, but then wants go to the next song when Music2 end - in this case Music3.
- When I click on Music1 it starts to play, but then wants go to the next song when Music1 end - in this case Music2.
etc... Easy Play list...
&&
When Music4 end, player must go to first song! In this case - Music1!
This is my code:
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Linq;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
using System.Runtime.InteropServices;<br />
<br />
namespace WindowsFormsApplication1<br />
{<br />
public partial class Form1 : Form<br />
{<br />
[DllImport("winmm.dll")]<br />
private static extern long mciSendString(string strCommand, StringBuilder strReturn, int iReturnLength, IntPtr hwndCallback);<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
if (openFileDialog1.ShowDialog() == DialogResult.OK)<br />
{<br />
textBox1.Text = openFileDialog1.FileName;<br />
}<br />
}<br />
<br />
private void button2_Click(object sender, EventArgs e)<br />
{<br />
listBox1.Items.Add(textBox1.Text);<br />
}<br />
<br />
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)<br />
{<br />
mciSendString("close MediaFile", null, 0, IntPtr.Zero);<br />
mciSendString("open \"" + listBox1.Items[listBox1.SelectedIndex].ToString() + "\" type mpegvideo alias MediaFile", null, 0, IntPtr.Zero);<br />
mciSendString("play MediaFile", null, 0, IntPtr.Zero);<br />
<br />
}<br />
<br />
private void button3_Click(object sender, EventArgs e)<br />
{<br />
mciSendString("close MediaFile", null, 0, IntPtr.Zero);<br />
}<br />
<br />
}<br />
}<br />
Please help!
modified on Monday, August 30, 2010 8:00 PM
|
|
|
|
|
It seems you want a notification when the current song is finished. I guess it is in the documentation somewhere, however things could be very simple: have a look at this CodeProject article Using mciSendString to play media files[^], I'm pretty sure it holds what you need.
|
|
|
|
|
Thanks for answer
Yep, i read this tutorial but i no have problem with playing (Its work for me), but with playlist. Idk how make going to the next song. )
Eg.
In listBox have:
C:/Music/Blablabla.mp3
C:/Music/Blablabla2.mp3
C:/Music/Blablabla3.mp3
And i want:
C:/Music/Blablabla.mp3 started.... Song.... End.
Now my program: Play song... When song end, make nothing.
I want when:
C:/Music/Blablabla.mp3 when song is end, go to
C:/Music/Blablabla2.mp3. When C:/Music/Blablabla2.mp3 end go to: C:/Music/Blablabla3.mp3. When C:/Music/Blablabla3.mp3 end, go to: C:/Music/Blablabla.mp3 (First song)
Etc
|
|
|
|
|
that should be easy: keep track of the current song (store the ListBox.SelectedIndex in a class member, say current ); when the song ends, increment that counter and read ListBox.Items[current] to get the next item, and start playing it. (It will throw an error when you reach the end of the list without explicitly checking for that!).
BTW: when you reply to your own message you get a MessageBox and nobody gets an e-mail notification, it is only by accident that I read your reply...
|
|
|
|
|
I few sites said to (in the js file) put the varible in <%= %> these tags but thats not doing any good. Is there some other part needed to this I'm missing. The javascript I'm using is in a file I included in my VS project.
|
|
|
|
|
It will only work if it's in the markup for your page not in a seperate javascript file.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
is there any way at all to get a value from one to the other? Well.. I don't need it to go two ways..
|
|
|
|
|
JavaScript file
function SomeFunction()
{
alert(myVar);
}
ASPX file
<script language='Javascript'>
var myVar = <%= SomeValue %>
</script>
<script src='Javscript.js' />
Code behind
public string SomeValue{ get; set;}
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Forgot to mention I'm working with a WPF app and the html is included with that. How would all this work and be placed in that?
|
|
|
|
|
Forgot? This is a critical piece of information that could have saved us botth a lot of time.
You can't use the <% %> syntax in this situation. There is no ASP.NET engine involved that will parse and render these tags.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Alright, and sorry. By the time I got to this problem I'd already been up most night. Lesson learned.. don't post the help topics when severely lacking sleep..
|
|
|
|
|
I have a string str = "123 abc b1c3 and so on"
i need to get fragments without spaces
string_array[0] = "123"
string_array[1] = "abc"
and so on
How can i do it?
|
|
|
|
|
str.Split(new char[]{' '});
|
|
|
|
|
split uses ' ' as delimiter and if i have more than one space?
|
|
|
|
|
str = str.Replace(" ", " ").Split(new char[]{' '});
|
|
|
|
|
|
works good!
|
|
|
|
|
Or, alternatively...
str = str.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|