1

I have a AxWindowsMediaPlayer control on my WinForm.

Everything works so far. But I can't resize or move the control.

I initialize the control like this:

mediaPlayer = new AxWMPLib.AxWindowsMediaPlayer();

mediaPlayer.CreateControl();
mediaPlayer.enableContextMenu = false;
((System.ComponentModel.ISupportInitialize)(mediaPlayer)).BeginInit();
mediaPlayer.Name = "wmPlayer";
mediaPlayer.Enabled = true;
mediaPlayer.Dock = System.Windows.Forms.DockStyle.Fill;
mediaPlayer.Size = this.Size;
this.Controls.Add(mediaPlayer);
((System.ComponentModel.ISupportInitialize)(mediaPlayer)).EndInit();
mediaPlayer.uiMode = "none";
mediaPlayer.URL = fileName;
mediaPlayer.settings.setMode("loop", true);

mediaPlayer.Ctlcontrols.play();

But the size ist always the same. How can I set the Size or the Bounds of this Controls?

Thanks for help

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
johnbraum
  • 276
  • 4
  • 18

2 Answers2

1

It is better do this in designer, rather than code.

In your code, you set the size of the player control as large as the form.

//occupies all the form's available space
mediaPlayer.Dock = System.Windows.Forms.DockStyle.Fill; 
//again, the player is the same size as form
mediaPlayer.Size = this.Size; 

In order to set the bound of the player control within the form, you can set the its AnchorStyle- anchoring the control to the edges of the form- and set the control's Location and Size properties.

mediaPlayer.Location = new Point(50, 50);
mediaPlayer.Size = new Size(this.ClientSize.Width - 100, this.ClientSize.Height - 100);
mediaPlayer.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
kennyzx
  • 12,845
  • 6
  • 39
  • 83
  • Okay. Now i added the mediaPlayer through the designer. Set it to visible=false and show it when I need him. And with Anchors it works fine... But why I can't create the instance in code and set its bounds? Weird.. Thanks for help! – johnbraum Dec 16 '14 at 15:18
0

For anyone who wants to zoom in on AxWindowsMediaPlayer

        axWindowsMediaPlayer1.stretchToFit = true;
        axWindowsMediaPlayer1.Width *= 2;
        axWindowsMediaPlayer1.Height *= 2;
Vulpi
  • 1