Click here to Skip to main content
15,170,651 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to make slide show work with time interval, But show some errors I am using medialooks SDK components. But application show some errors.

System.ArgumentNullException
  HResult=0x80004003
  Message=Value cannot be null.
Parameter name: path
  Source=mscorlib
  StackTrace:
   at System.IO.Directory.GetFiles(String path, String searchPattern)
   at CGEditor_WinForms.MainWindow.button1_Click(Object sender, EventArgs e) in E:\test work\CGEditor_WinForms\MainWindow.cs:line 997
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
   at PlaylistSample.Form1.CgEditorButton_Click(Object sender, EventArgs e) in E:\test work\Playlist Sample\Form1.cs:line 295
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at PlaylistSample.Program.Main() in E:\test work\Playlist Sample\Program.cs:line 17

  This exception was originally thrown at this call stack:
    [External Code]
    CGEditor_WinForms.MainWindow.button1_Click(object, System.EventArgs) in MainWindow.cs
    [External Code]
    PlaylistSample.Form1.CgEditorButton_Click(object, System.EventArgs) in Form1.cs
    [External Code]
    PlaylistSample.Program.Main() in Program.cs


What I have tried:

<pre lang="C#">  
private void button1_Click(object sender, EventArgs e)
        {
            string imgslideID = "";
            int imgslideposX = 50;
            int imgslideposY = 50;

            timer1.Interval = int.Parse(comboBox1.Text) * 1000;
            
            timer1.Start();
            

                if (m_strImagePath == null || m_strImagePath == string.Empty)
            {

            }
            System.Windows.Forms.FolderBrowserDialog openFolder = new System.Windows.Forms.FolderBrowserDialog();
            //System.Windows.Forms.DialogResult reopenFoldersult = openFolder.ShowDialog();
            if (openFolder.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                m_objEditor.CGObject.AddNewItem(openFolder.SelectedPath, imgslideposX, imgslideposY, 0, 1, ref imgslideID);
                m_objEditor.UpdateItemsList();
                string[] files = Directory.GetFiles(Dirpath, "*.Jpg");
                Dirpath = openFolder.SelectedPath;
                foreach (string file in files)

                {

                    int pos = file.LastIndexOf("||");

                    string FName = file.Substring(pos + 1);

                   

                }

            }
        }
Posted
Updated 26-Mar-21 4:09am
v2
Comments
CHill60 26-Mar-21 5:48am
   
What are the errors and where?
Richard MacCutchan 26-Mar-21 7:26am
   
Look at the first messages. you are calling some system method and passing a null value instead of a valid path.
Richard MacCutchan 26-Mar-21 8:01am
   
Well apart from the timer being started I cannot see anything that controls the interval or the display of the images.
Richard MacCutchan 26-Mar-21 8:07am
   
You need an event handler that is called for every timer tick. See Timer Class (System.Timers) | Microsoft Docs[^] for an example.
Richard MacCutchan 26-Mar-21 8:26am
   
Yes, can you?
Richard MacCutchan 26-Mar-21 9:10am
   
See my Solution below.
Richard MacCutchan 26-Mar-21 9:51am
   
Sorry, I cannot guess what you have done. Please use the Improve question link above and show us the actual code that you are using.
Richard MacCutchan 26-Mar-21 5:48am
   
"But show some error" ... "But application show some errors."
But you do not think it important to tell us what those errors are and where they occur?

Quote:
C#
string[] files = Directory.GetFiles(Dirpath, "*.Jpg");
Your Dirpath variable is null.

It's initialized on the following line:
C#
Dirpath = openFolder.SelectedPath;
I suspect you meant to have those two lines the other way round:
C#
Dirpath = openFolder.SelectedPath;
string[] files = Directory.GetFiles(Dirpath, "*.Jpg");
   
C#
public partial class Form1 : Form
{
    private string[] images;
    private int imageIX;
    private Bitmap MyImage;
    public Form1()
    {
        InitializeComponent();
    }

    private void button2_Click(object sender, EventArgs e)
    {

        System.Windows.Forms.FolderBrowserDialog openFolder = new System.Windows.Forms.FolderBrowserDialog();
        if (openFolder.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
            string Dirpath = openFolder.SelectedPath;
            images = Directory.GetFiles(Dirpath, "*.Jpg");
            imageIX = 0;
        }
        timer1.Interval = 5000;// int.Parse(comboBox1.Text) * 1000;
        timer1.Start();
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        // Sets up an image object to be displayed.
        if (MyImage != null)
        {
            MyImage.Dispose();
        }
        MyImage = new Bitmap(images[imageIX]);

        // Stretches the image to fit the pictureBox.
        pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
        pictureBox1.Image = (Image)MyImage;
        imageIX++;
        if (imageIX > 10)
            timer1.Stop();
    }
}
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900